Generating menu from content directory

32 views
Skip to first unread message

jgrin

unread,
Jul 22, 2011, 5:26:42 AM7/22/11
to Hyde
Now I use a menu generated from the site.yaml content data. The
starter site uses this as well. This works of course but in 0.4 I was
used to an autogenerated menu based on the contents of the contents
folder.

I cannot find the right way to do this kind of menu-generation in Hyde
0.8 but I guess it is still possible for the blog entry does something
similar.

Could someone provide me with an example?

Thanks in advance,

John

Grygoriy Fuchedzhy

unread,
Jul 22, 2011, 5:35:33 AM7/22/11
to hyde...@googlegroups.com
On Fri, Jul 22, 2011 at 02:26:42AM -0700, jgrin wrote:
> Could someone provide me with an example?

If I've understood correctly what you need, then you can add this to your
site.yaml:
> sorter:
> main_menu:
> attr: meta.main_menu

and then in the header of pages, which should appear in the menu add this:
> ---
> extends: base.j2
> title: Some title
> main_menu: 1
> ---

After this you can use following in your templates in order to generate menu:
> {% for res in site.content.walk_resources_sorted_by_main_menu() %}
> ...
> {% endfor %}

--
Grygoriy Fuchedzhy

Lakshmi Vyas

unread,
Jul 22, 2011, 6:17:42 AM7/22/11
to hyde...@googlegroups.com
The 0.8 equivalent code for
https://gist.github.com/72831 is:


~~~~~~~~~~~

<ul>
<li{% if not page.node.module %} class="selected" {% endif %}>
<a href="{{site.content.url}}">Home</a>
</li>
{% for module in site.content.child_nodes if not module.name == 'media' %}
<li {% if page.node.module == module %}class="selected"{% endif %}>
<a href="{{ module.url }}">{{ module.name|title}}</a>
</li>
{% endfor %}
</ul>

~~~~~~~~~~~~~~~~

> --
> You received this message because you are subscribed to the Google Groups "Hyde" group.
> To post to this group, send email to hyde...@googlegroups.com.
> To unsubscribe from this group, send email to hyde-dev+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/hyde-dev?hl=en.
>

jgrin

unread,
Jul 22, 2011, 6:29:41 AM7/22/11
to Hyde
After trying this I get a Type error from sorter.py. Attributename
must be a string? Probably a yaml error I suppose.

I don't have time now to investigate right now, I'll take it up this
evening.

You answer lifted a corner on how a sorter can be used and I now
understand what it should do. I'll try to get the definition right
tonight and will report back here.

Thanks for your fast reply!

John


On Jul 22, 11:35 am, Grygoriy Fuchedzhy <grygoriy.fuched...@gmail.com>
wrote:

jgrin

unread,
Jul 22, 2011, 3:45:18 PM7/22/11
to Hyde
> After trying this I get a Type error from sorter.py. Attributename
> must be a string? Probably a yaml error I suppose.

Yep, this one was due to fat fingers :)

I tried both methods and they both do the trick. But in different
ways...

The method Grygoriy suggested lists all pages that have a main_menu
field in the meta of the files, and get sorted accordingly. That I
like :)

The method Lakshmi suggest is indeed the old behaviour of Hyde 0.4. It
lists all index files in subdirectories. Every page has to be in its
own subdir. Although preferred by many, that has always annoyed me for
some reason.

So I'm inclined to go with Grygoriy's method here. I noticed a
drawback, a content file lacking the sort field will not be in the
menu. I tried to fix that by putting main_menu: 99 in the site.yaml
meta section. That got me much more menu content than I wanted, every
file gets listed. I tried messing with filters which helped but I
could not skip the blog entries.

Oh well, I suppose I'll just have to use the sortfield.

Thanks for all help!

Lakshmi

unread,
Jul 25, 2011, 7:40:43 AM7/25/11
to hyde...@googlegroups.com
You can also declare the sort field in meta.yaml files under any folder. This may help you skip unwanted files and folders.
Reply all
Reply to author
Forward
0 new messages