|
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 |
qUJy5Xg0ve7k Smarty Rookie
Joined: 15 Aug 2018 Posts: 15
|
Posted: Wed Aug 22, 2018 10:59 pm Post subject: |
|
|
In my example, I created foo and bar. So I would just have
Code: | $arr = array('bar', 'foo');
|
I created the names, so it's easy to have them in an array. I'm not sure why that would be impossible.
Code: | {capture name=columnA assign=columnA}
<td>I am columnA!</td>
{/capture}
{capture name=columnB assign=columnB}
<td>I am columnB!</td>
{/capture}
<tr>
{foreach from=$arr key=str}
{$smarty.capture.$str}
{/foreach}
</tr>
|
Now I can change the order of the columns by simply changing the order of the array. This actually maintains the business logic inside the array, which is created in the proper layer. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Aug 23, 2018 4:08 pm Post subject: |
|
|
Sorry to say it, but your example makes no sense.
What you are looking for is includes. Not captures.
You can use include inline to save on cache rendering. |
|
Back to top |
|
qUJy5Xg0ve7k Smarty Rookie
Joined: 15 Aug 2018 Posts: 15
|
Posted: Fri Aug 24, 2018 12:57 am Post subject: |
|
|
So you are suggesting that I put each column in its own file, call the files foo.tmpl, bar.tmpl, then do the include in the for loop instead of the capture? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Aug 24, 2018 8:51 pm Post subject: |
|
|
Sounds about right. Assuming the demonstrated example is indeed the way you use captures. |
|
Back to top |
|
qUJy5Xg0ve7k Smarty Rookie
Joined: 15 Aug 2018 Posts: 15
|
Posted: Mon Aug 27, 2018 4:08 pm Post subject: |
|
|
Update for future inquirers:
The bug fix was committed here: https://github.com/smarty-php/smarty/commit/8e09f97a147d6c637e541f61887b1ae893763bec
The code change is in libs/sysplugins/smarty_internal_compile_capture.php
The function compileSpecialVariable was changed to:
Code: |
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
{
return '$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl'.(isset($parameter[ 1 ])?", {$parameter[ 1 ]})":')');
}
|
|
|
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
|