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

How can I use {counter) in breadcrumb.tpl

 
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 -> General
View previous topic :: View next topic  
Author Message
mpatzekov
Smarty n00b


Joined: 23 Jun 2016
Posts: 2

PostPosted: Thu Jun 23, 2016 1:14 pm    Post subject: How can I use {counter) in breadcrumb.tpl Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Jun 23, 2016 6:26 pm    Post subject: Reply with quote

You didn't initialize the counter anywhere in your posted example.
Refer to documentation for details: http://www.smarty.net/docs/en/language.custom.functions.tpl#language.function.counter

And please format your code in [ code ] tags. Your posts are unreadable.
Back to top
View user's profile Send private message
mpatzekov
Smarty n00b


Joined: 23 Jun 2016
Posts: 2

PostPosted: Fri Jun 24, 2016 10:33 am    Post subject: Reply with quote

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


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

PostPosted: Fri Jun 24, 2016 11:49 pm    Post subject: Reply with quote

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
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 -> General 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