|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
maxhq Smarty n00b
Joined: 20 Nov 2006 Posts: 3
|
Posted: Mon Nov 20, 2006 3:36 pm Post subject: Evaluate delimiters after processing pre-filters |
|
|
I would like to change the left/right delimiters in a pre-filter. Currently, that's impossible.
Is there a way to move the evaluation of the left/right delimiters in Smarty_Compiler::_compile_file() past the execution of pre-filters?
I can see that the delimiters are used to "un-hide hidden xml open tags" before pre-filter execution. This is the only step that uses the delimiters before pre-filters. I don't know what this is for, but could it be moved after pre-filters? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
|
Back to top |
|
maxhq Smarty n00b
Joined: 20 Nov 2006 Posts: 3
|
Posted: Mon Nov 20, 2006 7:00 pm Post subject: Pre-filter not defined as plugin |
|
|
OK, good to know that it works for your plugin. Then maybe it just doesn't work for me because I only define my pre-filter via register_prefilter().
I have to confess that I don't know Smarty internals in depth, but looking at Smarty_Compiler.php, it tells me the following:
In line 236, $this->_load_filters() is called. I guess during this step your method smarty_function_include_clipcache() is called an sets the delimiters.
In line 240, local variables $ldq/$rdq are set with the delimiters, after that only these variables are used.
In line 247, calls to the filter functions are made. And this is the only place where my pre-filter function is called (because it's no plugin), so I have no chance to change the delimiters.
By the way, my pre-filter scans the template for a configuration directive to dynamically change the delimiters.
Currently only works with some preg_replace(). But I would like it to work by changing rdelim/ldelim.
Example: MyJavaScript.js.tpl
Code: | // <config>
// rdelim = ]
// ldelim = [
// </config>
<script>
function test() {
var some = '[$smarty.xxx]';
}
</script> |
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Nov 20, 2006 7:23 pm Post subject: |
|
|
Well...
are you trying to change the delimeters for the whole template or just sections of it? My method keeps the already set delimiters for the whole template but allows for various subsections to switch delimiters. I don't think you really want to dynamically assign delimiters at the whole template level. If you restrict it to subsections, you can probably get away with a compiler plugin that injects delimiter changing code.
eg: {set_delims left="[" right="]"}
Of course, to reset it you would have to do:
[set_delims left="{" right="}"]
All-in-all, even though I've implemented this myself (and FWIW), I think that changing delims in-template is probably not the best solution. |
|
Back to top |
|
maxhq Smarty n00b
Joined: 20 Nov 2006 Posts: 3
|
Posted: Tue Nov 21, 2006 6:49 am Post subject: |
|
|
I want to change them for the whole template. So far I haven't implemented compiler plugins, but I had already written a user function {setdelims...}. But then it showed that changing the delimiters only works for the next template beeing processed/included. E.g. it worked like that:
Code: | {setdelims left=".." right=".."}
{include file="WorksForThis.tpl"}
{$ButNotForThis}
{setdelims left=".." right=".."}
| And the second problem was that I could not write e.g. Code: | {setdelims right="*}"} | because then smarty stops processing at the first }.
That is why I decided to implement my own way of parsing configuration settings.
Why shouldn't it be good to change delims in a template? For me it seems the most readable solution as you only have to look into one file (the template) to know what the delims are.
And I also like to change them for the whole template, e.g. for a javascript include file that contains much smarty code. And it fits perfectly into my framework
May sound stupid, but one main reason for me to change the delims was that when I use
Code: | left_delimiter=/*{
right_delimiter=}*/ | then the JSEclipse plugin perfectly highlights the the javascript code.
By the way, Smarty is just great. I could not imagine starting a new medium/big size PHP web project without Smarty. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Nov 21, 2006 4:42 pm Post subject: |
|
|
Yes, thinking about it again, I see you are right. I don't think you can change delims mid-stream -- not easily anyways. Part of the problem is the way Smarty scans/lexes/parses a template. It uses a regex based mechanism which collects all relevant blocks at the outset (as opposed, say, to a traditional streaming scanner). So in general, I don't think there is a solution for this except for prefiltering. In that case, you would end-up with a solution that looks like my clipcache solution that I posted earlier. It removes blocks from the template (storing them in their own files) before Smarty sees them.
Why shouldn't a template declare its delimiters? For one, it increases the processing needs (you need two scans over the file) and for another, the environment is not supposed to be controlled by templates. I can see why you want to, but why not just pick one set of delimiters that will satisfy all your needs at once?
Best. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|