How to list existing categories if any, in a vertical sidebar

32 views
Skip to first unread message

Ibn Saeed

unread,
Aug 11, 2016, 10:27:27 AM8/11/16
to nikola-discuss
Hello

How to list existing categories if any, in a vertical sidebar.

I just need the category titles.

I found this in tags.tmpl

<%block name="content">
   
% if cat_items:
       
% if items:
           
<h2>${messages("Categories")}</h2>
       
% endif
       
% for text, full_name, path, link, indent_levels, indent_change_before, indent_change_after in cat_hierarchy:
           
% for i in range(indent_change_before):
               
<ul class="postlist">
           
% endfor
           
<li><a class="reference" href="${link}">${text}</a>
           
% if indent_change_after <= 0:
               
</li>
            % endif
            % for i in range(-indent_change_after):
                </
ul>
               
% if i + 1 < len(indent_levels):
                   
</li>
                % endif
            % endfor
        % endfor
        % if items:
            <h2>${messages("Tags")}</
h2>
       
% endif
   
%endif
   
% if items:
       
<div>
       
% for text, link in items:
           
% if text not in hidden_tags:
               
<span class="label large"><a href="${link}">${text|h}</span>
           
% endif
       
% endfor
       
</div>
    % endif
</
%block>



But it does not work .



Roberto Alsina

unread,
Aug 11, 2016, 10:34:03 AM8/11/16
to nikola-discuss
Well, that's for tags, and it only works in the tag list. It is possible to do something similar but it will take a little coding in the categories plugin.

--
You received this message because you are subscribed to the Google Groups "nikola-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nikola-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Warrick

unread,
Aug 11, 2016, 10:41:06 AM8/11/16
to Nikola—Discuss
On 11 August 2016 at 16:27, Ibn Saeed <ibns...@gmail.com> wrote:
> Hello
>
> How to list existing categories if any, in a vertical sidebar.
>
> I just need the category titles.
>
> [snip]
>
> But it does not work .

The variables used in your snippet work only on the “Tags and
Categories” page. We don’t provide them anywhere else.

If you want category titles on every page, there are two paths:

1) make a plugin that will add a category title list to your global
context. This has a rather ugly side effect of forcing rebuilds of all
files when you create a new category.
2) make a plugin that will create a .json file with your categories
list, and then use client-side JavaScript to display those. This will
make your category list invisible to people without JavaScript; it
will also be invisible until the page fully loads.

--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16

Roberto Alsina

unread,
Aug 11, 2016, 10:48:17 AM8/11/16
to nikola-...@googlegroups.com
3) Modify the categories plugin to generate that json file

Ibn Saeed

unread,
Aug 11, 2016, 12:06:28 PM8/11/16
to nikola-discuss, ral...@kde.org
I did hardcoded it into conf.py by adding the list in Global_Context 

Ibn Saeed

unread,
Aug 11, 2016, 5:01:38 PM8/11/16
to nikola-discuss
What is cat_items and cat_hierarchy is tags.tmpl

How to use them.

Roberto Alsina

unread,
Aug 11, 2016, 6:19:26 PM8/11/16
to nikola-discuss
Those things are only available in that page, and won't help you for what you are trying to do.

On Thu, Aug 11, 2016 at 6:01 PM Ibn Saeed <ibns...@gmail.com> wrote:
What is cat_items and cat_hierarchy is tags.tmpl

How to use them.

Reply all
Reply to author
Forward
0 new messages