|
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 |
stef70 Smarty n00b
Joined: 02 Sep 2006 Posts: 1
|
Posted: Sat Sep 02, 2006 6:25 pm Post subject: Adding escapes in literal |
|
|
I am new to smarty and there is one detail that I really dislike: the {literal} mecanism does not allow smarty tags inside it.
ock
There are several solutions to that problem (close & reopen the literal block or escape each { and }) but they all make the source unreadable.
I came up with a good idea: instead of trying to escape the { } from the document, escape the { } used by smarty.
This escaping could be limited to the inside of the {literal} block and only when requested.
For example, suppose that you have defined a tag {copyright lang="xxx"} that includes a copyright inside a comment of the specified language xxx.
You could write a piece of C++ code as follow:
{literal escape="@"}
#include <iosteam>
@{copyright lang="c++" @}
class Foo {
...
}
{/literal}
The advantage of specifiying the escape in the {literal} is that you can choose any character that is not common in the content. Also, the backward compatibility is insured since the default behavior is unchanged.
I do not know how {literal} is implemented but that feature should not be to difficult to do. Something like that probably:
(1) detect the end {/literal} marking the end of the block.
(2) if $escape is empty then stop here.
(3) for each '{' or '}' found in the block
if it is prefixed by $escape then discard that $escape
else replace the '{' and '}' by {ldelim} and {rdelim}
(4) process the resulting block with Smarty. |
|
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
|