Jump to content

php in .tpl files?


Guest perfectpage

Recommended Posts

Guest perfectpage

I want to include some php script in my .tpl files. I know this is not possible as it doesnt have a PHP extension. I opened"includes/boxes/categories.inc.php" and change the script to refer to "skins/Killer/styleTemplates/boxes/categories.php" and renamed the .tpl file to .php.

This worked with no errors, etc.

However if I put some PHP in, eg. <? date("jS"); ?> it doesnt display the PHP and it also actually displays the PHP code in the source code...

How can I achieve this?

Link to comment
Share on other sites

Hi,

You are missing the point of the template files. That point being that there is not PHP code in the templates.

If you wanted to put a code generated value into the template, simply use assign funtion. see sample below:

Insert into teplate

{DATE}




and in the xxx.inc.php file that includes your template, insert this code




	$tpl_name->assign("DATE",date("jS"));

good luck

Link to comment
Share on other sites

Guest jeromas

Goober999 is right, the .tpl files look like they're supposed to be XHTML, and the cart is set-up to allow you to run your PHP code and assign variables using the object declaration noted.

However, if you are desparate to have your .tpl files be parsed for PHP, you would need

to add the following handler to your server config (at least this is how it works in Apache)

Extension: .tpl Handler: application/x-httpd-php

That isn't Apache code btw

:rolly:

Adding handlers is pretty easy to do if you use a web host that has cPanel access. However, note that any time you add a handler to a file type, you're going to slow down your site, as now anytime Apache comes upon that extension, it will parse for whatever type of handler you added, even if nothing is there.

Link to comment
Share on other sites

and in the xxx.inc.php file that includes your template, insert this code

Sorry can you just elaborate on that slightly.

Where is this xxx.inc.php file?

Is it in the template folder for that skin, or how do we identify it otherwise?

I take it there isn't a central list of all the existing functions we could use?

That would be so handy wouldn't it....

Link to comment
Share on other sites

Guest perfectpage

Well this is what I tried:

In a template file I put something such as {RELATED_PRODUCTS} in the viewProd.tpl file. Then in the viewProd.inc.php (btw that is in the includes/content folder, midigod) I added a $body->assign... part to replace {RELATED_PRODUCTS} with the contents of another file.

For that I used fopen to get the file contents and replaced the {RELATED_PRODUCTS} part with all the contents. This worked, however, as soon as I put a simple <? echo "hello"; ?> in that file, all I get is the php enclosed in the tags displayed in the source code.

Is there some sort of function that ignores PHP code?

Link to comment
Share on other sites

Is there some sort of function that ignores PHP code?
Your question is loose. PHP functions include[_once], require[_once] inside any php script, interprets php code in any included(required) file as php code (must be enclosed with php marks). All others outside of php marks interprets as is. Any other PHP funtions related to manage any file content (fopen, file.....) interprets content of those files as is, if they are open LOCALLY .

If you want to get a final result of any php file into a variable, you have to 'call' this file using http into URL...like this:

$my_variable = readfile ("http://my.host.tld/my_file.php");

// or any HTML with php code inside
instead of 
$my_variable = readfile ("/my_file.php");
which interprets php file as is (source).



ADDED LATER

The right result wil be reached using join & file:
$my_variable = join ('', file ("http://my.host.tld/my_file.php"));

:unsure:

Link to comment
Share on other sites

  • 5 months later...

This is all well and good, but this also means that every time you do a little custom PHP on a site, you're making it that much harder to upgrade.

There doesn't seem to be an easy way to extend CubeCart w/o hacking into the core code, and that's quite simply frustrating. I've been working on a site based on WordPress and I've come to admire the elegant architecture which keeps not only themes (or skins) separate from the rest of the site—it also keeps plugins separate and includes numerous ways to hook the plugins into the code.

Granted, WordPress doesn't have to deal with the things a shopping cart does, but I think CC would greatly benefit from some similar architecture. However, I don't see how it's possible without a major overhaul.

Still, this seems a lot better than others I've looked at. I just wish there were a 'WordPress' of shopping carts.

Link to comment
Share on other sites

Guest gwizard

Yeah, same with ZenCart.

They did override directory that you can put your mods there and the core just looks it there is something in there and uses it if yes.

BTW, that's a very simple tweak we can use in CC as well.

Just a though.

Link to comment
Share on other sites

It is nowhere near a "simple tweak". In order to do it fully and properly, there are literally hundreds of places within the code where "hooks" need to be added. That does not mean the ordeal is not being examined and/or planned, but it is a huge code rewrite. But I agree it would be very nice.

;)

Link to comment
Share on other sites

Guest gwizard

I didn't say it would be easy on the implementation, I said it is easy on the design.

Besides, that kind of mod is more fit for Brooky to implement in the core and not us modders.

Let him asess the amount of time vs usability and reduce of complaints on each version update.

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