Jump to content

Including PHP


Guest

Recommended Posts

Hi all,

I would like to know if it is possible to include som external php code on top in one of the columns (i.e. left one). Like so: <?PHP include("../external/nav.php");?>.

This would enable me to use the same navigation as I have through out the rest of my php site. Is this doable?

Magnus J

Link to comment
Share on other sites

Yes, but I would like to know where to include it?

You can´t include php in the .tpl file, right? So where...?

And...

How?

Erh... I feel like three years old :-)

Link to comment
Share on other sites

it's a bit more advanced with CC3 it seems, but on the other hand HTML, PHP and CSS are all separated very nicely and the code looks clean and easy to change or make modifications to if you just know how to do it. The learning curve is probably alot higher than what you're used to from CC2, but the best things are rarely the easiest or what do you say? :P

to put it "simple", the tpl files in the skin directory has a "friend" by the same name with a php ending in the include directories. for example...

/skins/Classic/styleTemplates/boxes/categories.tpl

/includes/boxes/categories.inc.php

these two kinda "belong" to each other, the tpl file is the HTML template in which you put these cute {MARKS} inside, which you later populate with content from the corresponding php file.

then look in /index.php where it's being assembled like this:

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

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

/skins/Classic/styleTemplates/global/index.tpl

...is the corresponding template file for the root index file. this file is as close you get to a "real" HTML file. this is where you can change the order of the boxes for example, or maybe insert a totally new box on top of the left column? why not...

so, for your example you should perhaps create a new file pair and hook it up. try to see how one of the more simple boxes work and maybe copy that file and start making changes. looking how other things works is usually a good way of learning. the BEGIN and END comments along with the parse function is also quite interesting to check out for example.

this WILL require some studying from your side, it is quite complicated for the novice and maybe someone should write a real good documentation or HOWTO for this, but it will still be advanced....

I am by no mean an expert to this either and I've just recently started to play around with CC but I love this, CC3 is the only choice for me just because of this coding style and separation of code and HTML/CSS. I didn't like CC2 at all. I tried to work with zen-cart before but THAT was a true pain in the ass. CC3 is pure and clean, it feels modern and fresh. so... dont give up! :D

cheers,

rikard

Link to comment
Share on other sites

Thanks Rikard!

But... I can´t get my head around this.

Almost got it. This is what I´ve done.

In /index.php I put this:

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

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

In includes/boxes/extern.inc.php I put this:

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

$box_content->parse("extern");

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

In skins/Classic/styleTemplates/boxes/extern.tpl I put this:

<!-- BEGIN: extern -->

<table width=\"790px\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">

<tr>

<td>Extern nav?</td>

</tr>

</table>

<!-- END: extern -->

And in skins/Classic/styleTemplates/global/index.tpl I put this:

{EXTERN}

This adds a new "box" on top of the left column, as it should. The problem is that it displays the text "Extern nav?" that I put in the extern.tpl file. What I want is to display a non-CubeCart php page, for instance "Web root/externals/nav.php".

I have tried including this include ("../externals/nav.php"); in the extern.inc.php file but then nav.php just shows up on the very top of the page, above everything?

I´m lost...

Link to comment
Share on other sites

I think you're almost there, but your included PHP file probably outputs things directly on screen with print or echo commands. unfortunately you must make it into a string which you can render together with the rest of the page...

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

$box_content aboce should be the result of your PHP file. maybe that causes trouble for you having to rewrite your navigation file a little... but it should work... :)

/rikard

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...