Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Macro newbie question

Started by Muut Archive 10 years ago · 2 replies · 390 views
10 years ago

hello,
I have a huge site with more than 1500 pages.
On each of them I wold like add a 'see also' section which lists all related pages, like

TWIG
## See also
<ul>
{% for post in taxonomy.findTaxonomy({'category':'docs'}) %}
    <li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
<ul>

A macro is probably the best choice something like:

TWIG
{% macro see_also(category) %}
etc.

I have 2 precises questions:
1) in which file should I create this macro and in which folder?
2) how to call the macro inside the pages (sorry for this newbie question, but it's not so clear for me in the doc)

thanks for your help
senso++++

10 years ago

First of all, consider using the Related Pages plugin already available.

If that doesn't do what you want, then here's the general outline of what to do:

  1. Follow these instructions and inherit the theme you're currently using. This way you can update the base theme without losing your customizations.

  2. Create a new partial called something like user/themes/mytheme/templates/partials/relatedpages.html.twig that encapsulates the logic and formatting of the "see also" section you're trying to build.

  3. {% include %} that new partial into whatever page template you want it to appear: Twig docs.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1359 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2957 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago