PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/hyde/layouts/starter/content/advanced/sorter.html

http://github.com/hyde/hyde
HTML | 53 lines | 42 code | 11 blank | 0 comment | 0 complexity | 1e52eb3c3ef8c71ebb005f598c8382ff MD5 | raw file
 1---
 2index: 2
 3title: Sorting
 4tags:
 5    - sort
 6learning_order: 1
 7---
 8
 9Sorting
10=======
11
12There will come a time when you will need to list and sort resources. Hyde
13allows you to walk the site tree and sort the resources by the predefined
14settings in your configuration file.
15
16You can list and sort by name all your content files.
17
18{# With every sorter defined in the configuration file, nodes get a method
19   to call. Notice that in the first and last example the method is called
20   on the whole content of the site, while the second example shows how to
21   invoke it only on one specific node (in this case the current one).
22
23   Also, some new Jinja filters were used to style the output.
24#}
25{% for res in site.content.walk_resources_sorted_by_name() %}
26  * [{{ res.slug|capitalize|replace("-"," ") }}]({{ res.full_url }})
27    ({{ res.name }})
28{% endfor %}
29
30Or list only those in the current node (folder). In this case that would be
31all advanced topics.
32
33{# Have in mind that using the next example in a content page (like here) or
34   using it in a layout (Jinja template that is extended or include by
35   content pages) will yield very different results.
36
37   In this case it will be called only once, for this resource, and shown
38   only on this page. If it was in a layout, it would be called for EVERY
39   resource that uses that layout. In that case the context would be
40   different, the parent node of the resource could be different and the
41   results will probably be different too.
42#}
43{% for res in resource.node.walk_resources_sorted_by_index() %}
44  {{ loop.index }}. [{{ res.slug|capitalize }}]({{ res.full_url }})
45{% endfor %}
46
47Or sort files by type and then by size.
48
49{% for res in site.content.walk_resources_sorted_by_file_type() %}
50  * [{{ res.source_file.kind|upper }}] {{ res.name }}
51{% endfor %}
52
53{{ macros.render_bottom_article_nav() }}