Jump to content

Custom {BOX} rendering custom php results


Guest

Recommended Posts

Hi all, searching in the forums I found a way to add custom boxes with my own content as in this thread

I followed all instruccions, double checked grammar and spelling but my php content keeps rendering on top of my page and not in the content box!!!

Im lost a what to do since I been trying to solve this for a long time now...

;)

here is my code

in Index.php

include("includes/boxes/news.inc.php");

$body->assign("news",$box_content);




in news.inc.php




<?php 

include("include_news.php");

$box_content=new XTemplate ("skins/".$config['skinDir']."/styleTemplates/boxes/news.tpl");

$box_content->parse("news");

$box_content = $box_content->text("news"); 



?>






and in news.tpl






<!-- BEGIN: news -->



<!-- END: news -->

I tried NEWS doing UPPER CASE and lower case but that didnt work either

what am I doing grong???

thanks in advance :)

Link to comment
Share on other sites

You need to assign your content to a variable.

Example:

$box_content->assign("LANG_SALE_ITEMS_TITLE",$lang['front']['boxes']['sale_items']);

This assigns content to the variable {LANG_SALE_ITEMS_TITLE}, which would be placed into the template.

Just study the default CubeCart files for examples of how it's done.

Link to comment
Share on other sites

Thanks for the quick reply^^

I did check how others boxes are done...

but they are too complex for me to fully understand

my content is pulled from

include("include_news.php");

how do I get it INSIDE the box?

I know is silly but I tried

$box_content->parse("include_news.php");

of course it didnt work

it just keeps rendering on top of the page and not in the box {news} (I tried NEWS also XD) position T_T

Link to comment
Share on other sites

Try something like:

$content = include("include_news.php");

$box_content->assign("NEWS", $content);

$box_content=new XTemplate ("skins/".$config['skinDir']."/styleTemplates/boxes/news.tpl");

$box_content->parse("news");



$box_content = $box_content->text("news");




The first line is where the custom content gets assigned to a variable rather than spit out to the screen above everything else.



There was a post a while back that used the following code:


$file = file_get_contents("http://www.mysite.com/include_news.php");

$box_content->assign("NEWS", $file);




You might try that too if the above doesn't work.



In your template, place {NEWS} where you want that content to show up.


<!-- BEGIN: news -->

{NEWS}

<!-- END: news -->

Link to comment
Share on other sites

My curiousity got the better of me, so I did some research into capturing php output to a variable, and I think I found the 'proper' way to do it. (Webpage where I found it.)

ob_start(); // start buffer

include ("file-to-include.php");

$content = ob_get_contents(); // assign buffer contents to variable

ob_end_clean(); // end buffer and remove buffer contents

echo $content;




For use in CubeCart, this would translate as:


ob_start(); // start buffer

include ("include_news.php");

$content = ob_get_contents(); // assign buffer contents to variable

ob_end_clean(); // end buffer and remove buffer contents



$box_content->assign("NEWS", $content);

$box_content=new XTemplate ("skins/".$config['skinDir']."/styleTemplates/boxes/news.tpl");

$box_content->parse("news");



$box_content = $box_content->text("news");

Link to comment
Share on other sites

Guest dtmswebmaster

Hi all, searching in the forums I found a way to add custom boxes with my own content as in this thread

I followed all instruccions, double checked grammar and spelling but my php content keeps rendering on top of my page and not in the content box!!!

Im lost a what to do since I been trying to solve this for a long time now...

:)

here is my code

in Index.php

:)

include("includes/boxes/news.inc.php");

$body->assign("news",$box_content);




in news.inc.php




<?php 

include("include_news.php");

$box_content=new XTemplate ("skins/".$config['skinDir']."/styleTemplates/boxes/news.tpl");

$box_content->parse("news");

$box_content = $box_content->text("news"); 



?>






and in news.tpl






<!-- BEGIN: news -->



<!-- END: news -->




I tried NEWS doing UPPER CASE and lower case but that didnt work either

what am I doing grong???

thanks in advance 
Ok.. the only thing I see wrong here, is that you haven't called it up in the /skins/Your_Skin/styleTemplates/global/index.tpl file. In this file, you can add {news} to "link" it all and make it work. :) Also try moving

into the news.tpl file for it to add it within the box. :)... I hope this helps ya. :D

include("include_news.php");
Link to comment
Share on other sites

AlanT is right, includes do not work inside tpls (I tried :))

Markscarts

THAT DID IT!

thank you very much, and thanks everyone for being so supportive

^^

:)

Link to comment
Share on other sites

No problem, AGTH :)

BTW, I tried adding a news blog for one of my customers and kept having the same problem; it was nice to see that a member here found the way to code it in that post I gave above :)

Very useful info, IMO

For any other interested parties, this can usually be done without all the complication like this:

$file = file_get_contents("http://www.mysite.com/include_news.php");

$body->assign("NEWS", $file);

And then call it in index.tpl using {NEWS}

Is that how you did it, myka?

Link to comment
Share on other sites

Yep ^^ that's how =P

My site is getting really cool with all the stuff I learn in the forums, thanks to everybody, this is a great comunity

BTW

there's another way to do it...

its with iframes, very usefull, I added two Iframes to my index.tpl. In one iframe I got loaded the php stuff (they are news) and when clicked, the news get loaded in the main frame, looks pretty cool two.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...