View previous topic :: View next topic |
Author |
Message |
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu May 04, 2006 12:51 am Post subject: |
|
|
OpenMacNews wrote: |
<ste: clipcache id=test group=foo ttl=5 ldelim=<ste: rdelim=:ste> :ste>
BLAH BLAH BLAH
<ste: /clipcache id=test group=foo ttl=5 ldelim=<ste: rdelim=:ste> :ste>
causes an error:
Fatal error: Smarty error: [in test.tpl line 59]: syntax error: unrecognized tag 'clipcache' (Smarty_Compiler.class.php, line 580) in /path/to/Smarty.class.php on line 1095
which, i'm guessingm may be a problem with my non-standard delims of '<ste:' & ':ste>', though not sure. wan't entirely clear to me if the prior page's delim def'n support was 'in there' already ...
|
There is a modicum of support for private delims but you seem to be mis-using them. Recall the earlier example:
Code: | {clipcache id=foo group=bar ttl=300 ldelim=(: rdelim=:)}
{foobar} <-- not interpreted as a smarty tag in this block
(: include file=foobar.txt :) <-- interpreted as a smarty tag in this block
{/clipcache id=foo group=bar ttl=300 ldelim=(: rdelim=:)} |
the ldelim and rdelim attributes are used to change from the current delimiters [eg: {, }] to new delimiters within the clipcache block [eg: (:, ]. In your case, you don't seem to actually change the delims and that confuses the parsing. It seems you can simply use:
Code: |
<ste: clipcache id=test group=foo ttl=5 :ste>
BLAH BLAH BLAH
<ste: /clipcache id=test group=foo ttl=5 :ste>
|
Within the clipcache block, you would still use your custom delims. Of course, I wouldn't push that feature too hard
HTH |
|
Back to top |
|
OpenMacNews Smarty Rookie
Joined: 03 Aug 2004 Posts: 34 Location: Floating on Io's Methane Seas ...
|
Posted: Thu May 04, 2006 1:09 am Post subject: |
|
|
well, for a moment there, i was encouraged
changing to recommended code:
Code: | <ste: clipcache id=test group=foo ttl=5 :ste>
BLAH BLAH BLAH
<ste: /clipcache id=test group=foo ttl=5 :ste> |
i'm unfortunately still seeing the error:
Quote: | Fatal error: Smarty error: [in test.tpl line 59]: syntax error: unrecognized tag 'clipcache' (Smarty_Compiler.class.php, line 580) in /path/to/Smarty.class.php on line 1095 |
so, it seems that it may be something else ...
this functionality will be hugely useful ... i'm happy to play 'guinea pig' as much as needed, as your intereste dictates!
cheers |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu May 04, 2006 3:51 am Post subject: |
|
|
Heh. My mistake. As I said, there is a modicum of support for this right now The regex is very simple atm and does not allow spaces between the clipcache tagname and the delimiters, so this should work:
Code: | <ste:clipcache id=test group=foo ttl=5 :ste>
BLAH BLAH BLAH
<ste:/clipcache id=test group=foo ttl=5 :ste> |
However, I updated the regex (without bumping the version) in the posted code so you can test that if you like. Personally, I think it looks kinda funny but I guess it should be supported. Hmmm, it seems the parsing could use some attention for the next release. The need to mirror the attributes in the close tag bothers me.
Thanks for testing and reporting issues, OpenMacNews! |
|
Back to top |
|
OpenMacNews Smarty Rookie
Joined: 03 Aug 2004 Posts: 34 Location: Floating on Io's Methane Seas ...
|
Posted: Thu May 04, 2006 5:26 am Post subject: |
|
|
hi boots,
Quote: | However, I updated the regex (without bumping the version) in the posted code so you can test that if you like.
|
updated to bumped code.
with or without the spaces, per:
Code: | <ste:clipcache id=test group=foo ttl=5 :ste>
BLAH BLAH BLAH
<ste:/clipcache id=test group=foo ttl=5 :ste> |
i now get:
Code: | Fatal error: Using $this when not in object context in /path to/plugins/prefilter.clipcache.php on line 74 |
checking @ 74:
Code: | $write_path = rtrim( $this->compile_dir, "/\\" ) . DIRECTORY_SEPARATOR; |
which looks like you added the rtrim from an later post ...
Quote: | Personally, I think it looks kinda funny |
same here. BUT, with my 'custom' delims, i *know* with certainty that i can search/replace open/close tags without error ... worth the tradeoff for me.
Quote: | Thanks for testing and reporting issues, |
heh, it's a work of art in progress!
thanks,
richard |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu May 04, 2006 7:44 am Post subject: |
|
|
OpenMacNews wrote: | Code: | $write_path = rtrim( $this->compile_dir, "/\\" ) . DIRECTORY_SEPARATOR; |
which looks like you added the rtrim from an later post ... |
yipes, my bad. $this should be $compiler. I silently updated the code again without bumping versions.
Thanks! |
|
Back to top |
|
OpenMacNews Smarty Rookie
Joined: 03 Aug 2004 Posts: 34 Location: Floating on Io's Methane Seas ...
|
Posted: Thu May 04, 2006 7:54 am Post subject: |
|
|
hi,
boots wrote: | $this should be $compiler. I silently updated the code again without bumping versions. |
and with that, no more errors, and page displays properly ...
in the morning i'll start thinking about how to test/benchmark.
cheers & thx again!
richard |
|
Back to top |
|
OpenMacNews Smarty Rookie
Joined: 03 Aug 2004 Posts: 34 Location: Floating on Io's Methane Seas ...
|
Posted: Wed May 10, 2006 10:19 pm Post subject: |
|
|
hi boots,
i've gotten far enuf along in ZF+Smarty to actually start looking at {clipcache} usage in detail when in ZF.
in my Zend_View class extension i've:
===============================================
...
protected function _run($template)
{
$this->_smarty->assign('smarty', $this);
$this->_smarty->register_clipcache();
$this->_smarty->display($template);
}
...
===============================================
which i'm fairly certain (?) is the right place to call register_clipcache();
BUT, if in:
test.tpl:
===============================================
<ste: clipcache id=test group=foo ttl=0 :ste>
BLAH
<ste: /clipcache id=test group=foo ttl=0 :ste>
===============================================
nav to the calling page viz Zend FrontController results in:
Warning: Smarty error: unable to read resource: "/webapps/resources/templates/test.tpl#test" in /webapps/tools/smarty/libs/Smarty.class.php on line 1095
checking in Smarty.class.php ...
/**
* trigger Smarty error
*
* @param string $error_msg
* @param integer $error_type
*/
function trigger_error($error_msg, $error_type = E_USER_WARNING)
{
1095 trigger_error("Smarty error: $error_msg", $error_type);
}
suggestions where to look for trouble?
cheers,
richard |
|
Back to top |
|
Amadiere Smarty Rookie
Joined: 20 Feb 2006 Posts: 5
|
Posted: Wed May 17, 2006 10:12 am Post subject: |
|
|
Excellent function!
I have just had a little bit of a problem with an install on my Windows setup.
In prefilter.clipcache.php on line 76 (ish): Code: | $file_name = $compiler->_current_file.'#' . $id; |
When I examined why I was having a load of "failing to create a directory", it didn't seem to be permissions problem. But was due to the fact that I believe the variable $compiler->_current_file has a different output depending on the operating system.
The way it appears to be used here is as if it contains the name of the file only. However, on Windows (or I should say "my setup") it returned the entire path. Which meant when it was concatinating it to create the name of the directory you had something along the lines of: Code: | C:/whataver/compile/clipcache/C:/whatever/content/template.tpl |
My fix isn't too nice, rather crude actually - but it suits my scenario. I have an array of global configs that I provided the 'smarty_prefilter_clipcache' function access to, before altering the above mentioned line to:
Code: | $file_name = str_replace($config[STATUS]['content_dir'].'\\',"",$compiler->_current_file).'#' . $id; |
I'm quite happy (currently) with my fix. If anyone spots any flaws in my knowledge I wouldn't mind some constructive critism.
Again, an excellent function boots! Great work! |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed May 17, 2006 2:56 pm Post subject: |
|
|
Hi Amadiere.
Thanks for the comments! I traced this issue with OpenMacNews on IRC and discovered that the problem seems to be a little bit more involved (you are close, though). I actually have a fix but I have forgotten to update the code (it is sitting on my home machine so I can't do it right now). I can sum it up like this: you can NOT use absolute paths to call templates. With my fix, you can convert an absolute path to a relative path but only if the absolute path is part of the template_dir path -- otherwise it fails. So basically, in its current state clipcache does not support:
- resources
- multiple template dirs
- absolute paths outside of the template_dir
and absolute paths inside the template_dir will only be supported if you manually convert them to relative paths with a helper function that I (will) provide on the Smarty_ClipCache class.
I'll post the updated fix tonight. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu May 18, 2006 7:26 am Post subject: |
|
|
I've decided to post the code at the wiki. I'm no longer updating the code in this thread but we can still discuss the addon here
Get the latest 0.1.7 version: http://smarty.incutio.com/?page=ClipCache
Note that the new Smarty_ClipCache::absolute2relative() method has not yet been tested and will likely be improved in a future version. |
|
Back to top |
|
HeadY Smarty n00b
Joined: 26 Jun 2007 Posts: 3
|
Posted: Wed Jul 18, 2007 3:06 pm Post subject: |
|
|
Hi,
nice plugin!
But i have a problem with dynamic IDs. Ill do:
Code: | {assign var="cacheID" value="user_"|cat:$data.user_id}
{clipcache id=$cacheID group=profile ttl=300} |
in my Template and get:
Code: | Warning: Smarty error: unable to read resource: "box_right_news.tpl#->_tpl_vars['cacheID']" in /.../Smarty/Smarty.class.php on line 1095
|
Whatīs the ID and GROUP for when i cant assign them with some dynamic content?
But the Performance is great!
11 DB Queries -> 0,084 sec
04 DB Queries -> 0,029 sec |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Jul 19, 2007 8:05 am Post subject: |
|
|
Hi.
Thanks for the nice comments! Admittedly, ClipCache is somewhat under achieving in regards to dynamic assignments. From memory alone, it occurs to me that this is probably caused by the fact that the logic for the ClipCache replacements occur in a prefilter (ie: at runtime) which do not fully consider evaluating the assigned parameter values as full-fledged Smarty expressions when generating the resulting code.
That's probably because I never needed that feature for myself ... but of course, patches are welcome
Best! |
|
Back to top |
|
HeadY Smarty n00b
Joined: 26 Jun 2007 Posts: 3
|
Posted: Mon Aug 13, 2007 3:48 pm Post subject: |
|
|
Well,
i got the right cache ID with a "fix" in the prefilter.clipcache.php:
Code: | $this = &$compiler;
eval ("\$id = $id;");
$file_name = $compiler->_current_file.'#' . $id; |
But then the script loads the first cached Data
I donīt understand why and how the Smarty/Clipcache System works. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Aug 13, 2007 5:50 pm Post subject: |
|
|
Hmmm. I strikes me that eval'ing the id is not the right solution here. Maybe better to use something like $compiler->_parse_var( $id ) ? Haven't thought about it too hard, so I don't know for sure.
Anyways, sorry if the code isn't clear enough. {clipcache} attempts to do something that Smarty wasn't designed for; as a result, it pushes the plugin architecture a bit more than is usual for most addons/plugins. If you have specific questions on how the system works, I'll try to answer them. |
|
Back to top |
|
|