Guest perfectpage Posted August 22, 2005 Share Posted August 22, 2005 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? Quote Link to comment Share on other sites More sharing options...
goober999 Posted August 22, 2005 Share Posted August 22, 2005 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 Quote Link to comment Share on other sites More sharing options...
Guest jeromas Posted August 24, 2005 Share Posted August 24, 2005 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 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. Quote Link to comment Share on other sites More sharing options...
Guest Posted August 24, 2005 Share Posted August 24, 2005 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.... Quote Link to comment Share on other sites More sharing options...
Guest perfectpage Posted August 24, 2005 Share Posted August 24, 2005 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? Quote Link to comment Share on other sites More sharing options...
convict Posted August 24, 2005 Share Posted August 24, 2005 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: Quote Link to comment Share on other sites More sharing options...
Guest Posted January 26, 2006 Share Posted January 26, 2006 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. Quote Link to comment Share on other sites More sharing options...
Guest gwizard Posted January 26, 2006 Share Posted January 26, 2006 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. Quote Link to comment Share on other sites More sharing options...
Guest Posted January 27, 2006 Share Posted January 27, 2006 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. ;) Quote Link to comment Share on other sites More sharing options...
Guest gwizard Posted January 27, 2006 Share Posted January 27, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.