Sidebar template freetags

Creating and modifying plugins.
Post Reply
User avatar
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Sidebar template freetags

Post by yellowled » Sun Dec 11, 2011 1:46 pm

The last option's description for the freetags sidebar plugin states: "If set the template is used to render the tag sidebar. In the template there is a variable <tags> available which contains the list of tags in the format <tagName> => array(href => <tagLink>, count => <tagCount>)"

Does anyone have an example for how to use this? I don't get it at all.

YL
amazon Wishlist - Serendipity-Podcast (German only, sorry)

User avatar
onli
Regular
Posts: 2362
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Sidebar template freetags

Post by onli » Sun Dec 11, 2011 2:31 pm

I dont have an example at hand, but the code says:

Code: Select all

arsort($tags);
$tagsWithLinks = array();
foreach ($tags as $tag => $count) {
    $tagsWithLinks[$tag] = array(
        'count' => $count,
        'href'  => $taglink . serendipity_event_freetag::makeUrlTag($tag),
    );
}
$serendipity['smarty']->assign('tags', $tagsWithLinks);
$template = serendipity_getTemplateFile($template, 'serendipityPath');
$serendipity['smarty']->display($template);
So there is a smarty-variable $tags you can iterate over. Every tag in tags is an array with the name and the count, so something like

Code: Select all

{foreach from="tags" key="tagname" item="tag"}
    <li><a href="$tag.href">$tagname ($tag.count)</a></li>
{/foreach}
should work.

User avatar
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Sidebar template freetags

Post by yellowled » Sun Dec 11, 2011 2:55 pm

onli wrote:something like

Code: Select all

{foreach from="tags" key="tagname" item="tag"}
    <li><a href="$tag.href">$tagname ($tag.count)</a></li>
{/foreach}
should work.
Nope, no output at all.

Might be related to the fact that I don't have the plugin sitting in the sidebar but do emit it on the archives page using serendipity_showPlugin, I guess. Hmm. Bummer.

YL
amazon Wishlist - Serendipity-Podcast (German only, sorry)

User avatar
onli
Regular
Posts: 2362
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Sidebar template freetags

Post by onli » Sun Dec 11, 2011 3:14 pm

The relevant code is in serendipity_event_freetag, the sidebar-plugin just toggles the option. This will only work if the event_freetag-plugin is executed.

And i'm not sure with the syntax of the smarty-code, regard it more as pseudo-code probably needing correction.

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

Re: Sidebar template freetags

Post by Timbalu » Sun Dec 11, 2011 3:49 pm

The extended tpl is working with,

Code: Select all

			{foreach from=$entry.freetag.tags.tags item="tag"}
				{$tag}
			{/foreach}
maybe you need to use same.
Or just have a look what {$tags|print_r} says.
Regards,
Ian

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

User avatar
onli
Regular
Posts: 2362
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Sidebar template freetags

Post by onli » Sun Dec 11, 2011 3:52 pm

maybe you need to use same.
That's a different part of the plugin. That's the code for one entry and not referenced by the option of the sidebar-plugin. Probably not what is wanted (a list of all tags, i thought).
Or just have a look what {$tags|print_r} says.
Good idea.

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

Re: Sidebar template freetags

Post by Timbalu » Sun Dec 11, 2011 3:57 pm

Yepp, I wanted to say ...something similar (like $tags.tag) ;-)
Regards,
Ian

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

User avatar
onli
Regular
Posts: 2362
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Sidebar template freetags

Post by onli » Sun Dec 11, 2011 6:07 pm

Ah, ok. That's of course possible, though the code seems to inidcate otherwise.

Post Reply