Jump to content

PHP in template?


Guest uplift
 Share

Recommended Posts

Guest uplift

I've done a google search before posting this, i know it's been covered but all results are as old as 2007

I know i can't include PHP directly in a template

but i can assign a variable such as {MY_PHPCODE}

and include the code in a separate file or function?

Can anyone tell me how to do this?

I am trying to add PHP to the viewproduct template.

Thanks

Link to comment
Share on other sites

Basically every template has a corresponding includes page - viewProd.tpl corresponds to /includes/content/viewProd.inc.php - the tpl has all the html parts, the includes file all the php code and functions.

Link to comment
Share on other sites

but i can assign a variable such as {MY_PHPCODE}

and include the code in a separate file or function?

A direct answer is: you can't. The PHP code in CC uses the XTemplate system to build a string of HTML code and stores that code in a string variable until it gets spit out from the server and sent to your browser. At no time would any part of CC and the XTemplate system "re-digest" the contents of these variables containing the HTML code looking for more PHP code to execute.

See if someone might have a different idea about modifying CC over at www.cubecartforums.org.

Link to comment
Share on other sites

A direct answer is: you can't.

Yes you can. I do it all the time and so do mods. As long as you use the correct syntax in the includes file, you can create any custom code you want and call it in the templace as the OP is looking to do.

Link to comment
Share on other sites

Sorry, as I read the intent of the OP wanting a work around to make it *seem* like PHP is in the TPL file, that is, run the TPL file itself through the PHP parser. The OP acknowledges that PHP can't exist in the TPL file, and I directly confirmed that. Maybe it was bad phrasing ("I am trying to add PHP to the viewproduct template.").

Now, as for mods, there is a discussion just started in the appropriate forums for that.

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.

 Share

×
×
  • Create New...