View Full Version : Php file
Hello
Been trying to include a php file on my index with no joy. The only way iv been able to display it, is be assigning it a smarty template. The problem with that is the file has a live countdown which smarty cache messes up. Had no joy with the {literal}or{php} tags, wondering if theres a way of assigning to a .tpl but breaking that 1 tpl file out of the cache.
any ideas hints tip be great :)
Thanks
Nole
Can't you just include the actual code, direct into the index.php file as part of the page, then do a call using a designated tag for the index.tpl that's how I do anything like that, or keep the file seperate and do a "required file" or include type thing direct in the index.php file.
lol im such donkey...
It worked with a little playing round with the counter :D
Thanks AM
Hmm hi again
Must be having some kind of prolonged brain fart today. When including the code into the index.php or using required file ,include . I wasnt able to control where it would display, either above the header or below the footer. So i put the contents of the php file in a variable but without assigning that variable to smarty im not able to call it in the index.tpl.
Just thankful this is my last bit to my upgraded site, not sure if this is more frustrating than my spacebar dying
Nole
The easiest possible way to do stuff like this is to duplicate existing content sections and php bits, by simply copying them and renaming them slightly, then adding your own content into them as needed.
Say for example, you already have:
include_once('elements'.DIRECTORY_SEPARATOR.'searc h_box.php');
In the index.php file
You duplicate the search_box.php file, rename the new one to new_box.php and then add the new box code into the index.php page, so that it is actually parsed.
include_once('elements'.DIRECTORY_SEPARATOR.'new_b ox.php');
You would then do the same with the relevent template in the index.tpl file...
The following code displays the contents of search_box.tpl on the index page:
{include file="elements`$DIRECTORY_SEPARATOR`search_box.tpl"}
duplicate that file and then rename the new copy to something else, such as:
{include file="elements`$DIRECTORY_SEPARATOR`new_box.tpl"}
and add that code where you want it on the index.tpl template file, so that it actually displays the new_box tremplate code where you want it.
Then go into new_box.tpl and edit the template code to suite your needs, so that it displays the relevent code that you've put in new_box.php
That's a fairly rough way of looking at it, but once you've kinda got the hange of what i'm saying, it's easy from there on in. It also means you have seperate filesfor your custom work and keep your content blocks nice and seperate.
Probably not the easiest or best way of explaining what I mean though... ><
There is another guide to adding content blocks, somewhere on here, which explains it, but buggered if I could find it.
Hope that doesn't actually confuse you more than helps... :p
Hi
Thanks again AM
I got ya, plus not sure if i could get anymore confused :o
Im already able to include php blocks by doing what you said but all included php files need to be assigned to smarty to work with the tpl file.
IntroSites code:
$aYourOuput = "The result of your query etc that you want printed";
$oSmarty->assign('aYourOuput', $aYourOuput);
So iv been using the above code for all my php block files and it works well. but as i dont want this file cached, i cant use it.
Anyways thanks again for help
Nole
How's about a javascript include? You said it's just a countdown, so there'll be no real SEO benifit in having the content in your code, so this might just work for you.
So, have a standalone php file generating your countdown and have it echo out as Javascript using document write: http://www.mediacollege.com/internet/javascript/basic/document-write.html
Then, modrewrite (htaccess) so a call for yourfile.js grabs yourfile.php and use a standard javascript call on the page.
Top of the head solution btw, you'll need to figure out the logistics yourself
So iv been using the above code for all my php block files and it works well. but as i dont want this file cached, i cant use it.
Ah ok, in that case, not really using that method myslef (I use some pretty unorthadox ways of doing stuff at times), if you want to find out how to exclude an assigned insert like you've done, I would have said go over to the official Smarty forums and ask there, there must be some code or another than can be used to disclude a single tag like that.
I'd say someone on here would probably know, but nobody else seems to be being very vocal at the moment, must be the release of v3 or something has people hidden away in their lairs redoing their sites.
http://www.smarty.net/
http://www.phpinsider.com/smarty-forum/
Not sure how much you've used smarty, but it's amazing what you can do with it.
Andy - Interesting approach. Why I love what we do, i'd have not thought of it from the angle you have, there's so many different solutions for problems... :)
Thanks guys, will check out them links :)
The php file is a ebay api rest call that gets product info of items ending within 30s to 2mins. Its then runs a javascript countdown timer for each product.
Bit like a dog with a bone now :)
Nole
Yay sorted
I put my counter info into index.tpl <head> </head> and used
{* absolute path, or relative to $trusted_dir *}
{include_php file='/path/to/myfile.php'}
Had to rewrite some of the php file because the include tags wont work with global vars but so far so good.
Theres other ways, like creating {insert} or {dynamic} smarty plugins functions.
Isnt it amazing what you can learn when you read the manual :D
Nole