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

Dynamic list of links

Started by Muut Archive 10 years ago · 1 replies · 460 views
10 years ago

Hey, new to Grav - I'm looking to have a list of links that content editors can edit, stored as URL + Description, and have this list appear on every page of my Grav site. How would I go about doing this?

10 years ago

I've added a footer on every page of the website using a regular Grav markdown page as a source for the content, which can be edited by content editors like you describe:


  1. Add this code in /user/themes/[themename]/partials/base.html.twig where you want the links list to appear:
TWIG
{% block links %}
  {% set linkspage = pages.find('/links') %}
  {% if linkspage %}
     {% include 'partials/links.html.twig' %}
  {% endif %}
{% endblock %}

  1. Add file links.html.twig to the same /partials folder:
    HTML
    <div id="links">
    {{ linkspage.content }}
    </div>
    

  1. Add file /user/pages/links/links.md where you have your editable links list:

--- markdown
title: links routable: false ⁣

My Links List

Link1
Description 1 here lorem ipsum

Link2
Description 2 here lorem ipsum

Link3
Description 3 here lorem ipsum

TXT


`routable: false`ensures [yourdomain.com]/links/ throws a 404 if you try to navigate to it directly.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1351 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4062 9 years ago
Archive · by Muut Archive, 9 years ago
1 2948 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago