View previous topic :: View next topic |
Author |
Message |
Angel_bcn Smarty n00b
Joined: 15 Nov 2003 Posts: 4
|
Posted: Sun Nov 16, 2003 12:11 am Post subject: Generating static HTML code... Possible bug? |
|
|
I'm trying to use Smarty to generate static HTML code... and I'm finding a weird problem.
My code is something like this:
$tpl = new Smarty;
$tpl->use_sub_dirs = false;
$tpl->caching = true;
$tpl->force_compile = true;
for ( $i=0;$i<count(...);$i++) {
$tpl_data = function that gets the data from a database($i);
$tpl_template = function that gets the template name from a database($i);
$tpl->assign_by_ref("TPL_DATA",$tpl_data);
$tpl->fetch($tpl_template);
function that copies the generated file in the cache directory to my destination directory;
}
This code works perfect whenever the template name changes within the loop... but in case that the template name is the same... the file that appears in the cache file has only the firts line that is the one that includes the time stamp and expiration thing generated by Smarty.
I know that I'm not using Smarty on a very standard way... but this behaviour is driving me crazy... any ideas? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Nov 16, 2003 3:50 am Post subject: |
|
|
Looks like you are trying to pre-cache contents? I'm a little thrown by your description because I would think that the cache file for the case of re-fecthing for the same template name would contain the results from the last fetch, not the first since you have force_compile = true.
At anyrate, I think you want to look into Multiple Caches Per Page.
HTH |
|
Back to top |
|
Angel_bcn Smarty n00b
Joined: 15 Nov 2003 Posts: 4
|
Posted: Sun Nov 16, 2003 10:37 am Post subject: |
|
|
Yes the idea is use the cache feature to generate the page and then copy it to the location I want to. Before I posted that I already had a look and tried with Multiple Caches Per Page and the results are the same.
Note that before re-fetching I copy the file from the cache to another location... the problem is when I re-fetch using the same template name the result cache file has only the lfirst line that is the one with the time generation and the time expiration information...
In the trials I've even deleted the compiled file just to see if there is a compilation problem... but there is no compilation problem...
Any more ideas around? |
|
Back to top |
|
Angel_bcn Smarty n00b
Joined: 15 Nov 2003 Posts: 4
|
Posted: Wed Nov 19, 2003 5:20 pm Post subject: |
|
|
OK, I've found the bug... The problem is at the _process_template function.
There are a couple of 'include_once' sentences that have to be 'include' sentences... Those are the ones that are used to get the compiled template into the $_smarty_results variable.
Any chance this bug is corrected and deployed in the next smarty release?
I don't have my laptop right now here and cannot provide 100% of the details of the bug... sorry... but if you look at the first post of this thread you might understand the reason why.
Thanks. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Nov 19, 2003 5:26 pm Post subject: |
|
|
you didn't indicate with version of smarty you use. 2.6.0-RC3 doesn't have a _process_template()-method and there are no include_once()-statements in the _process_template()-method of 2.5.0. |
|
Back to top |
|
Angel_bcn Smarty n00b
Joined: 15 Nov 2003 Posts: 4
|
Posted: Thu Nov 20, 2003 6:12 am Post subject: |
|
|
Sorry... I was using 2.3.1.... my big mistake.... Now upgraded to 2.6.0.
Anyhow... can you please explain how is composed the name of the file stored at the cache directory?... Or, how can I get access to it directly from the smarty variable?
Thanks. |
|
Back to top |
|
maw Smarty Rookie
Joined: 18 Apr 2003 Posts: 8 Location: Wellington, New Zealand
|
Posted: Wed Dec 10, 2003 2:00 am Post subject: Static HTML |
|
|
I use Smarty to generate static html, but with a different approach. We have an internal test website for development (something like http://website), this runs smarty as you normally would, but with no cacheing - it is for development after all. Then when you call a page with ?save (e.g. http://website/index?save) the approriate files are created/copied to a temp directory. I then quickly check these and upload them to the live website. I use the command:
Code: | $source = $webpage->fetch($template); |
to fetch the html to a string and the save that to a file, no need to worry about what is happening on the filesystem. Also I can parse that string to extract the linked files (images, css, js, etc). |
|
Back to top |
|
|