-
Notifications
You must be signed in to change notification settings - Fork 714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
{capture} doesn't working as I expect #135
Comments
We have issues with Template: {assign var="accountMenu" value=[
0 => [
'link' => '/account/',
'label' => 'Overview'
],
1 => [
'class' => 'spacer'
],
2 => [
'link' => '/invoices/',
'label' => 'Invoices',
'itemsCount' => $customerDebt,
'visible' => $customerDebt > 0
],
3 => [
'link' => '/new-orders/',
'label' => 'New orders',
'itemsCount' => $customerNewOrdersCnt
],
4 => [
'link' => '/orders-history/',
'label' => 'Orders history',
'itemsCount' => $customerOrdersCnt
],
5 => [
'link' => '/quotes/',
'label' => 'Quotes',
'itemsCount' => $customerQuotationsCnt
],
6 => [
'link' => '/favorites/',
'label' => 'Favorites',
'itemsCount' => $customerWishlistCnt
],
7 => [
'class' => 'spacer'
],
8 =>[
'link' => '/mailings/',
'label' => 'Newsletters and notification settings'
],
9 => [
'link' => '/settings/',
'label' => 'Personal settings'
],
10 => [
'class' => 'spacer'
],
11 => [
'link' => '/account/logout/',
'label' => '%icon%Logout',
'icon' => 'icon-logout',
'class' => 'logout'
]
]}
<ul>
{foreach item=menuItem from=$accountMenu}
{if !empty($menuItem.class)}
{capture name="itemClass"}class="{$menuItem.class}"{/capture}
{elseif $menuItem.link eq $currentPageUrl}
{capture name="itemClass"}class="active"{/capture}
{else}
{capture name="itemClass"}{/capture}
{/if}
{if !empty($menuItem.linkClass)}
{capture name="linkClass"}class="{$menuItem.linkClass}"{/capture}
{else}
{capture name="linkClass"}{/capture}
{/if}
{if !empty($menuItem.icon)}
{capture name="linkIcon"}<span class="{$menuItem.icon}"></span>{/capture}
{else}
{capture name="linkIcon"}{/capture}
{/if}
{if !isset($menuItem.visible) || $menuItem.visible}
<li {$smarty.capture.itemClass}>
{if !empty($menuItem.link)}
<a href="{$menuItem.link}" {$smarty.capture.linkClass}>
{$menuItem.label|replace:'%icon%':$smarty.capture.linkIcon}
{if isset($menuItem.itemsCount)}
<span>({$menuItem.itemsCount|default:0})</span>
{/if}
</a>
{/if}
</li>
{/if}
{/foreach}
</ul> Smarty <ul>
<li class="active">
<a href="/account/" >
Overview
</a>
</li>
<li class="spacer">
</li>
<li >
<a href="/invoices/" >
Invoices
<span>(200)</span>
</a>
</li>
<li >
<a href="/new-orders/" >
New orders
<span>(2)</span>
</a>
</li>
<li >
<a href="/orders-history/" >
Orders history
<span>(10)</span>
</a>
</li>
<li >
<a href="/quotes/" >
Quotes
<span>(3)</span>
</a>
</li>
<li >
<a href="/favorites/" >
Favorites
<span>(5)</span>
</a>
</li>
<li class="spacer">
</li>
<li >
<a href="/mailings/" >
Newsletters and notification settings
</a>
</li>
<li >
<a href="/settings/" >
Personal settings
</a>
</li>
<li class="spacer">
</li>
<li class="logout">
<a href="/account/logout/" >
<span class="icon-logout"></span>Logout
</a>
</li>
</ul> But after update to <ul>
<li >
<a href="/account/" >
Overview
</a>
</li>
<li >
</li>
<li >
<a href="/invoices/" >
Invoices
<span>(200)</span>
</a>
</li>
<li >
<a href="/new-orders/" >
New orders
<span>(2)</span>
</a>
</li>
<li >
<a href="/orders-history/" >
Orders history
<span>(10)</span>
</a>
</li>
<li >
<a href="/quotes/" >
Quotes
<span>(3)</span>
</a>
</li>
<li >
<a href="/favorites/" >
Favorites
<span>(5)</span>
</a>
</li>
<li >
</li>
<li >
<a href="/mailings/" >
Newsletters and notification settings
</a>
</li>
<li >
<a href="/settings/" >
Personal settings
</a>
</li>
<li >
</li>
<li >
<a href="/account/logout/" >
Logout
</a>
</li>
</ul> Code used to render template: require_once __DIR__ . '/vendor/autoload.php';
$smarty = new Smarty();
$templateVars = [
'currentPageUrl' => '/account/',
'customerDebt' => 200,
'customerNewOrdersCnt' => 2,
'customerOrdersCnt' => 10,
'customerQuotationsCnt' => 3,
'customerWishlistCnt' => 5,
];
foreach ($templateVars as $variable => $value) {
$smarty->assign($variable, $value);
}
$smarty->display('capture.tpl'); If I change |
Ok, I have compared compiled templates of - <li <?php echo Smarty::$_smarty_vars['capture']['itemClass'];?>
+ <li <?php echo isset($_smarty_tpl->_cache['__smarty_capture']['itemclass']) ? $_smarty_tpl->_cache['__smarty_capture']['itemclass'] : null;?> Smarty |
So, the issue can be reproduced using {capture name="testMe"}Hello, {$username}{/capture}
{$smarty.capture.testMe|var_dump}
Compiled templates diff: -echo var_dump(Smarty::$_smarty_vars['capture']['testMe']);
+echo var_dump(isset($_smarty_tpl->_cache['__smarty_capture']['testme']) ? $_smarty_tpl->_cache['__smarty_capture']['testme'] : null); |
Thanks for your input. The fix is now in the master branch |
{capture} doesn't working as I expect, practically output is null:
Ex: list.tpl
and listing_data.tpl:
I mention that in the previous version that worked well
The text was updated successfully, but these errors were encountered: