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

[PATCH] {capture append="..."}

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
jablko
Smarty Rookie


Joined: 07 Apr 2006
Posts: 6

PostPosted: Tue Jul 31, 2007 7:52 pm    Post subject: [PATCH] {capture append="..."} Reply with quote

http://cgi.sfu.ca/~jdbates/tmp/smarty/200707310/patch

This patch was part of my Summer of Code project for Gallery last summer, to add an AJAX interface to the item administration system. The project is being merged into Gallery's trunk and this patch seems like a candidate for upstream.

It adds an "append" attribute to the {capture} compiler function, symmetric with the "assign" attribute. Like "assign" calls $this->assign(..., ob_get_contents()), this "append" attribute calls $this->append(..., ob_get_contents()).

This patch modifies ~10 lines and modifications are limited to _compile_capture_tag

The Gallery AJAX item admin interface uses the "append" attribute to divide templates' output into separate variables. In this way, one template can render both HTML output and the JavaScript to update that HTML after an AJAX callback:

<div id="foo"{if expr} style="display: none"{/if}>
[...]
</div>
{capture append="callbackOutput"}
{if expr}
document.getElementById("foo").style.display = "none";
{else}
document.getElementById("foo").style.display = "";
{/if}
{/capture}

HTML output is still returned by $smarty->fetch, but we use an output filter to replace content with $callbackOutput if the request was initiated by XmlHttpRequest.

Thanks, Jack
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Aug 01, 2007 9:26 am    Post subject: Reply with quote

looks good to me.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mohrt
Administrator


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

PostPosted: Wed Aug 01, 2007 1:35 pm    Post subject: Reply with quote

added to CVS, please give it a test.
Back to top
View user's profile Send private message Visit poster's website
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 -> Feature Requests 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