Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Capture Raw Smarty Code in Block Plugin

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
mattejames
Smarty Rookie


Joined: 15 Jan 2008
Posts: 7

PostPosted: Fri Feb 24, 2012 6:09 pm    Post subject: Capture Raw Smarty Code in Block Plugin Reply with quote

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. Smile

Thanks in advance.
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Fri Feb 24, 2012 6:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Feb 24, 2012 7:24 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Fri Feb 24, 2012 7:30 pm    Post subject: Reply with quote

Monte was probably talking about {$smarty.ldelim} or {ldelim} as {lbrace} does not exist…
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Feb 24, 2012 7:35 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mattejames
Smarty Rookie


Joined: 15 Jan 2008
Posts: 7

PostPosted: Fri Feb 24, 2012 8:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP