|
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 |
mpatzekov Smarty n00b
Joined: 23 Jun 2016 Posts: 2
|
Posted: Thu Jun 23, 2016 1:14 pm Post subject: How can I use {counter) in breadcrumb.tpl |
|
|
Hi to all! Since I am new to smarty I was wondering how I am able to do the folowing thing in breadcrumb.tpl. This is my code:
<ol vocab="http://schema.org/" typeof="BreadcrumbList">
<li class="breadoneline" property="itemListElement" typeof="ListItem"><a class="home" href="{if isset($force_ssl) && $force_ssl}{$base_dir_ssl}{else}{$base_dir}{/if}" property="item" typeof="WebPage" title="{l s='Home'}"><i class="icon-home"></i><span property="name" class="breadtitle breadtinyfix">Home</span></a><meta class="uniquebread" property="position" content="1"></li>
{if isset($path) AND $path}
<span class="navigation-pipe"{if isset($category) && isset($category->id_category) && $category->id_category == (int)Configuration::get('PS_ROOT_CATEGORY')} style="display:none;"{/if}>{$navigationPipe|escape:'html':'UTF-8'}</span>
{if $path|strpos:'span' !== false}
<span class="navigation_page">{$path|@replace:'<a ': '<span><li class="breadoneline" property="itemListElement" typeof="ListItem">
<a itemprop="url" '|@replace:'data-gg="">': ' property="item" typeof="WebPage">
<span property="name" class="breadtitle">'|@replace:'</a>': '</span>
</a>
<meta class="uniquebread" property="position" content="{counter}" ></li></span>'}
</span>
{else}
{$path}
{/if}
{/if}
</ol>
Note the two sections in red color. The first URL should always have value for content = 1. The second, third, forth, etc. URLs in the breadcrumbs should have respectively values 2, 3, 4, 5, etc. And since I was wondering how to do this, I decided to try with {counter}. However, using {counter} prints only {counter} (the same as it is written) as value for content.
Does anybody know how to correctly do this?
Thank you in advance! |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
mpatzekov Smarty n00b
Joined: 23 Jun 2016 Posts: 2
|
Posted: Fri Jun 24, 2016 10:33 am Post subject: |
|
|
Oh, yes. I forgot to mention that I actually did the following thing. And I didn't mark the code as [ code ] because I can't use colors or any kind of highlighting within the code. But if you insist...
Ok, so here's the code...
Code: | <ol vocab="http://schema.org/" typeof="BreadcrumbList">
<li class="breadoneline" property="itemListElement" typeof="ListItem"><a class="home" href="{if isset($force_ssl) && $force_ssl}{$base_dir_ssl}{else}{$base_dir}{/if}" property="item" typeof="WebPage" title="{l s='Home'}"><i class="icon-home"></i><span property="name" class="breadtitle breadtinyfix">Home</span></a><meta class="uniquebread" property="position" content="{counter start=1 skip=1}"></li>
{if isset($path) AND $path}
<span class="navigation-pipe"{if isset($category) && isset($category->id_category) && $category->id_category == (int)Configuration::get('PS_ROOT_CATEGORY')} style="display:none;"{/if}>{$navigationPipe|escape:'html':'UTF-8'}</span>
{if $path|strpos:'span' !== false}
<span class="navigation_page">{$path|@replace:'<a ': '<span><li class="breadoneline" property="itemListElement" typeof="ListItem">
<a itemprop="url" '|@replace:'data-gg="">': ' property="item" typeof="WebPage">
<span property="name" class="breadtitle">'|@replace:'</a>': '</span>
</a>
<meta class="uniquebread" property="position" content="{counter}" ></li></span>'}
</span>
{else}
{$path}
{/if}
{/if}
</ol>
|
This code prints value 1 in the first case. But the values for the other URLs in the breadcrumb remain {counter}. The second case somehow can't be executed, thus it prints {counter}. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Jun 24, 2016 11:49 pm Post subject: |
|
|
You can't use a function inside a text string, it is just treated as text. If you do:
{counter assign="mycount"}
Then {$mycount} will contain the counter value and you can use $mycount inside double quoted strings. It looks like you have things nested inside single quotes, so its a little more complicated than that. But this should send you the right direction. Maybe add another:
|@replace:"%mycount%":$mycount
and put %mycount% inside the string. so the whole thing:
Code: | <ol vocab="http://schema.org/" typeof="BreadcrumbList">
<li class="breadoneline" property="itemListElement" typeof="ListItem"><a class="home" href="{if isset($force_ssl) && $force_ssl}{$base_dir_ssl}{else}{$base_dir}{/if}" property="item" typeof="WebPage" title="{l s='Home'}"><i class="icon-home"></i><span property="name" class="breadtitle breadtinyfix">Home</span></a><meta class="uniquebread" property="position" content="{counter start=1 skip=1}"></li>
{if isset($path) AND $path}
<span class="navigation-pipe"{if isset($category) && isset($category->id_category) && $category->id_category == (int)Configuration::get('PS_ROOT_CATEGORY')} style="display:none;"{/if}>{$navigationPipe|escape:'html':'UTF-8'}</span>
{if $path|strpos:'span' !== false}
{count assign="mycount"}
<span class="navigation_page">{$path|@replace:'<a ': '<span><li class="breadoneline" property="itemListElement" typeof="ListItem">
<a itemprop="url" '|@replace:'data-gg="">': ' property="item" typeof="WebPage">
<span property="name" class="breadtitle">'|@replace:'</a>': '</span>
</a>
<meta class="uniquebread" property="position" content="%mycount%" ></li></span>'|@replace:"%mycount%":$mycount}
</span>
{else}
{$path}
{/if}
{/if}
</ol> |
|
|
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
|