Jump to content

PHP Include in a .tpl file


Guest TrueCHoJiN

Recommended Posts

Guest TrueCHoJiN

I'm of the understanding that PHP code gets stripped out of the .tpl files while they get processed. That was apparent after adding this line to my server's httpd.conf file "AddType application/x-httpd-php .tpl"; and seeing then that even then no PHP code would get processed.

So I guess my question is, in the Killer skin, how would you add an PHP include statement right where the navigation bar is? (I'm just going to replace CC's menu with my own) (I know where to add it, just not the syntax) if your interested; here is the menu (it's pretty cool), it gets generated from your CubeCart catagories :whistle:

>> MENU THAT I'M TRYING TO ADD TO THE KILLERS SKIN'S CATBAR <<

Ideally I would just like to include an XML variable tag (i.e. {MENU}) right in the ../boxes/catagories.tpl, but everytime I make all the modfications (like making menu.inc.tpl & menu.tpl, etc..) I can only insert an XML variable tag in ../globals/index.tpl??? I can't ever include any XML variable tags in any other .tpl files??? I know you guys know how to do this :cry:

markscarts?, akido (I think I PM'd you akido)?, convict?, estelle (if your reading this estelle, thanks for the popcorn trail thing, i will implement it this week, just been really busy)...

Link to comment
Share on other sites

PHP behind the category bar is found in includes/boxes/categories.inc.php - and the xml variable {CATEGORIES} is assigned in the stores root index.php, while the categories.tpl file is assigned in categories.inc.php with the new XTemplate assignation.

Just look at these four files, index.php, includes/boxes/categories.inc.php,

skins/. . ./styleTemplates/boxes/categories.tpl and

skins/. . ./styleTemplates/global/index.tpl and you will find the complete story of how they all work together. :whistle:

BTW, you are right you cannot use php in a .tpl file - the .tpl files differ from other html and xml file in that regard.

Link to comment
Share on other sites

Guest TrueCHoJiN

Right, I get that; because I have added my own XML variables (i.e {TEST}, {NEWS}, etc.) before. So I get that you have to make a test.inc.tpl file, test.tpl file, and add lines to the index.php. But I guess what I was wondering was why when I do what I previously mentioned... I can only add an XML variable tag (i.e. {MENU}) to ../globals/index.tpl... It doesn't work if I add an XML tag to ../boxes/catagories.tpl? What gives? Wrong syntax somewhere. The tags work fine in ../global/index.tpl, just not in any other *.tpl...

So are you essentially saying that I should add my PHP include statement for my menu to the ../includes/boxes/categories.inc.php file instead of trying to create a new XML variable tag and inserting the tag into ../boxes/catagories.tpl?

Link to comment
Share on other sites

You have to assign a content to template variable (you called it XML) in appropriate php file. Temlate is a parsed html document that means template variable could be a cluster of any html, javasript, flash.....but the main ground of variables is a variable content.

Every template can have a sections which are parsed separately/repeately - thats the advantage and thats the second main reason of templating system to use dynamic content for the same html code. The first is an independent html content written outside of php code. So if you want to assign something you should be sure what and where to assign. Global index.tpl uses variable templates. Content of global variable templates is generated by another template having own template variables thats the general matter. PHP code is the brain.

There doesnt exist any problem to write your javascript code to a right place (categories.tpl) manually just try it as a first.

Link to comment
Share on other sites

Anyway, I was thinking that if you looked closely at the files I mentioned, you could figure this out. The reason you can't make these variables useful in other templates would be if you are assigning them in index.php . . . pointing them to global/index.tpl

Variables are used in boxes/categories.tpl: {LANG_HOME} {DATA.cat_name} and {LANG_SALE_ITEMS}

These variables are assigned in includes/boxes/categories.inc.php

Have a look and you will see.

While you are there, you should also have a look at how the parsing is specified; compare with the cues in the template file that look like html comments :whistle:

Link to comment
Share on other sites

Guest TrueCHoJiN

markscarts:

OK, I think see better now how and where variables are assigned (i.e. {LANG_HOME} in ../boxes/categories.tpl), so then {LANG_HOME} is quite different from say ({SESSION} in ../global/index.tpl), where one is set to a statement and the other is set to an entire file.

convict:

You have to assign a content to template variable (you called it XML) in appropriate php file.

I thought {SESSION}, {CATAGORIES}, etc. were called XML variables, that's what markscarts .pdf on editing boxes said?

There doesnt exist any problem to write your javascript code to a right place (categories.tpl) manually just try it as a first.

True, not a problem as I have added a static test menu to catagories.tpl that contained only HTML & javascript, but to have a working dynamically database genrated menu, I need to add my PHP code, not just javascript and html for a static menu, which I can't be added to the catagories.tpl.

markscarts: - convict:

So we are back to the orignal question. Should I add the PHP menu code to the ../includes/boxes/categories.inc.php file and then set the variable {MENU} in that file, and call it from catagories.tpl? If so, what would the syntax be for setting a PHP include to a content variable? $box_content->assign(somethingPHPincludesomething);??

OR

Do I create an entirely new menu.tpl and menu.inc.php file, and try to include a template in a template?

[EDITED:]

Scratch that, I can't just make a new menu.tpl and stick my code in there because it still will nuke the PHP code. So I have to either insert my code into ../includes/boxes/categories.inc.php or a simliar PHP file, but the syntax of doing that exatcly is what is bugging... I will keep looking through all the include files to try and find an example of something similar...

Link to comment
Share on other sites

Guest TrueCHoJiN

OK, since it doesn't look like I'm going to get an answer that my tiny mind can understand (or a response to my last question either). $20 via PayPal to anyone one can include my index2.php (my menu file) into my ../Killer/../catagories.inc.php file. So if anyone wants $20 for five miuntes of work, just PM me. The menu (fully working) is below, I just need it where the cat nav bar is. I can zip and send any file, oh, and btw, I guess I was hoping for asap, if possible...

<MENU HERE>

Link to comment
Share on other sites

  • 1 month later...

OK, since it doesn't look like I'm going to get an answer that my tiny mind can understand (or a response to my last question either). $20 via PayPal to anyone one can include my index2.php (my menu file) into my ../Killer/../catagories.inc.php file. So if anyone wants $20 for five miuntes of work, just PM me. The menu (fully working) is below, I just need it where the cat nav bar is. I can zip and send any file, oh, and btw, I guess I was hoping for asap, if possible...

<MENU HERE>

Was this issue ever resolved?

Link to comment
Share on other sites

  • 1 month later...
Guest TrueCHoJiN

I had estelle help me out a while ago...

She checked the menu.php file that I had slated for include, and converted all of the echo statements in it.

She added this insert statment >>> <div align="center">{JAVASCRIPT_MENU}</div> to the catagories.tpl.

Also added this >>> include ('menu.php'); $box_content->assign("JAVASCRIPT_MENU",$menu_html); to catagories.inc.tpl, and that was about it to get it to work.

But I ended up gong with a different menu system in the end anyway, but it was nice to see the Xtreeme DHTML Menu working with CubeCart's catagories, pretty slick.

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