Freetag smarty code help

Creating and modifying plugins.
Post Reply
User avatar
Mangek
Regular
Posts: 85
Joined: Tue Jun 24, 2008 1:08 am
Location: Sweden
Contact:

Freetag smarty code help

Post by Mangek » Fri Aug 26, 2011 7:28 pm

Gentlemen,

As you're probably fully aware by now I'm not a programer, but I have this habbit of dissecting code, sometimes successfully, sometimes...not so much..

I'm using the extended smarty output and I'm trying to mimic way categories are output (it's still a work in progress, but have a look here).

It looks pretty good, but I have a problem with the trailing comma, as you can see. The categories have this line of code

Code: Select all

{if not $smarty.foreach.categories.last}, {/if}
which I tried to reproduce as

Code: Select all

{if not $entry.freetag.last}, {/if}
but that wouldn't work.

I have also tried

Code: Select all

{if not $entry.freetag.tags.last}, {/if}
{if not $entry.freetag.tags.tags.last}, {/if}
neither of which worked.

I'm assuming I got the coding wrong, hoping there is a way to limit it to all but the last tags. Any suggestions? :)

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Freetag smarty code help

Post by Timbalu » Fri Aug 26, 2011 8:05 pm

Assuming your extended-smarty code is somehow like the example one

Code: Select all

{if isset($entry.freetag.extended) && $entry.freetag.extended == 1}
	{if $entry.freetag.tags.tags}
		<div class="serendipity_freeTag">{$entry.freetag.tags.description}
			{foreach from=$entry.freetag.tags.tags item="tag"}
				{$tag}
			{/foreach}
		</div>
	
		{if $is_single_entry or $is_preview}
			{$entry.freetag.related.description}
			<ul class="serendipity_freeTag_related">
			{foreach from=$entry.freetag.related.entries item="link"}
				<li>{$link}</li>
			{/foreach}
			</ul>
		{/if}
	{/if}
{else}
	{$entry.freetag}
{/if}
the right code using smarty iterations last
http://www.smarty.net/docsv2/en/languag ... .iteration
should look like

Code: Select all

			{foreach from=$entry.freetag.tags.tags item="tag"}
				{$tag}{if not $smarty.foreach.tag.last},{/if}
			{/foreach}
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian

User avatar
Mangek
Regular
Posts: 85
Joined: Tue Jun 24, 2008 1:08 am
Location: Sweden
Contact:

Re: Freetag smarty code help

Post by Mangek » Fri Aug 26, 2011 8:19 pm

Hello Ian,

My code is a slimmed version of the example, I've removed the containing div, the "description" and related tags so I can get it inline after the categories. This is what I have now, with your code ammended:

Code: Select all

<span class="tags">
	{if isset($entry.freetag.extended) && $entry.freetag.extended == 1}
		{if $entry.freetag.tags.tags}
			{foreach from=$entry.freetag.tags.tags item="tag"}
				{$tag}{if not $smarty.foreach.tag.last},{/if}
			{/foreach}
		{/if}
	{/if}
</span>
{if not $smarty.foreach.tag.last},{/if} produces no commas, however. :(

Edit:
It needed name="tag" as well. {foreach from=$entry.freetag.tags.tags item="tag" name="tag"} works. Thanks a bunch! :) :)

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Freetag smarty code help

Post by Timbalu » Sat Aug 27, 2011 9:09 am

Oh yes: {foreach} loops also have their own variables that handle properties. These are accessed with: {$smarty.foreach.name.property} with “name” being the name attribute. Sorry.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian

User avatar
Mangek
Regular
Posts: 85
Joined: Tue Jun 24, 2008 1:08 am
Location: Sweden
Contact:

Re: Freetag smarty code help

Post by Mangek » Sat Aug 27, 2011 2:37 pm

Don't sweat it, if I didn't have to work a little on the problems myself I'd never learn now would I. ;)

Thanks again. :)

Post Reply