|
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 |
mattejames Smarty Rookie
Joined: 15 Jan 2008 Posts: 7
|
Posted: Fri Feb 24, 2012 6:09 pm Post subject: Capture Raw Smarty Code in Block Plugin |
|
|
Hello all,
I'm trying to use a block plug-in and capture the raw smarty content within the block. I've thought of a few ways to do this, but only one that I know of how to implement it.
Option 1: Create a pre-filter that looks for tags of this block type and adds in a {literal} right after the block starts and a {/literal} right after the block ends. (Not super-elegant, but I can actually do this.)
Option 2: Figure out some way to add a {literal} block programmatically from the block itself when the block opens. (A. I'm not sure this is even possible. B. If it is, I certainly don't know how to do it.)
Option 3: Some other brilliant suggestion you folks might have.
Thanks in advance. |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Fri Feb 24, 2012 6:51 pm Post subject: |
|
|
I've actually discussed this with Uwe a couple of months ago. The only way to do this (right) is option 1. {literal} is a special lexer-mode that cannot be activated "just like that". Sorry… _________________ Twitter |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Feb 24, 2012 7:24 pm Post subject: |
|
|
You could do this with a prefilter as such:
create your tags, say we call them "escape":
Code: | {escape}
This is some smarty {$tag} stuff we don't want {parsed}
{/escape} |
The prefilter would find blocks of {escape}...{/escape} content, then replace all instances of { and } with {$smarty.lbrace} and {$smarty.rbrace} respectively, and remove the escape tags. I have already done this with online documentation. I also did html-escapement in this block, which is why {literal} didn't suffice.
[edit] are you wanting to just display this content as text, or actually capture it? Maybe my method works for another purpose...
Last edited by mohrt on Fri Feb 24, 2012 7:44 pm; edited 2 times in total |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Fri Feb 24, 2012 7:30 pm Post subject: |
|
|
Monte was probably talking about {$smarty.ldelim} or {ldelim} as {lbrace} does not exist… _________________ Twitter |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Feb 24, 2012 7:35 pm Post subject: |
|
|
Actually its {$smarty.lbrace} and {$smarty.rbrace} I think {lbrace} and {rbrace} might have existed long ago, but were pulled in favor of the former syntax. The difference between "ldelim" and "lbrace" is that lbrace will always print "{" regardless of the smarty delimiters. (fixed in post) |
|
Back to top |
|
mattejames Smarty Rookie
Joined: 15 Jan 2008 Posts: 7
|
Posted: Fri Feb 24, 2012 8:26 pm Post subject: |
|
|
mohrt wrote: |
[edit] are you wanting to just display this content as text, or actually capture it? Maybe my method works for another purpose... |
I wanted to capture the raw code so I could process it at my discretion.
Thanks for the tips guys! |
|
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
|