Sidebar template freetags

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

Sidebar template freetags

Post by yellowled »

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
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Sidebar template freetags

Post by onli »

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.
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Sidebar template freetags

Post by yellowled »

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
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Sidebar template freetags

Post by onli »

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.
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Sidebar template freetags

Post by Timbalu »

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
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Sidebar template freetags

Post by onli »

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.
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Sidebar template freetags

Post by Timbalu »

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
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Sidebar template freetags

Post by onli »

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