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

How to make list of gallery pages?

Solved by pamtbaau View solution

Started by JMM 6 years ago · 2 replies · 413 views
6 years ago

Hi everyone, I want to know how is it possible to create a gallery page (I have some of those) and automatticly make links to be shown on a page where the user can choose which gallery to visit.

MARKDOWN
### [Cambio de Madrinas 2014](/festejos/galeria/2014/cambio%20de%20madrinas%202014)

### [Comunidad Española en Querétaro celebrando a la Virgen de la Covadonga](/festejos/galeria/2014/comunidad%20española%20de%20querétaro)

### [Halloween 2014](/festejos/galeria/2014/halloween%202014)

### [Halloween infantil 2014](/festejos/galeria/2014/halloween%20infantil%202014)

### [Posada en Puebla 2014](/festejos/galeria/2014/posada%20en%20puebla%202014)

### [Posadita 2014](/festejos/galeria/2014/posadita%202014)

### [Presentación de nuestra Nueva Madrina 2014 / 2015 Sofía González Hermida](/festejos/galeria/2014/presentación%20de%20nuestra%20nueva%20madrina%202014)

This is the markdown I use in the gallery selection page and want to make hrefs to any new gallery. I'm sorry if my english is bad and my explanation is not clear. (I speak spanish)

6 years ago Solution

@mera.inventio, If I understand correctly, you want a page that automatically generates a list of available galleries in you site.

If so, a possible solution could be to add taxonomy tags to your gallery pages and create a collection based on these tagged pages. Then loop through the collection and create a list of anchors.

When you create a new gallery page or update an existing, the generated list will automatically be updated.

The following outlines the steps needed:

  • Create an inherited theme based on theme 'Photographer' you are using. See Theme Inheritance steps 1-5
  • Add a taxonomy to the pages that contain a gallery, like:
    YAML
    ---
    title: Cambio de Madrinas 2014
    taxonomy:
    category: gallery
    ---
    

    For docs on collections see https://learn.getgrav.org/16/content/collections

  • Create a page 'galleries.md' that will contain links to all galleries. Add a collection definition to its header:
    YAML
    ---
    title: Listado de galerías
    content:
    items:
       '@taxonomy.category': gallery
    ---
    

    For docs on creating a collection on taxonomies see https://learn.getgrav.org/16/content/collections#taxonomy-collections

  • Create a new template in your inherited theme named '/themes/mytheme/templates/galleries.html.twig' and loop through the collection of galleries to create a list of anchors. E.g.:

    TWIG
    {% extends 'partials/base.html.twig' %}
    
    {% block content %}
     {% for gallery in page.collection() %}
         <a href="{{ gallery.url }}"><h3>{{ gallery.title }}</h3></a>
     {% endfor %
    {% endblock %}
    

Of course, you will need to add some extra html elements to create a suitable layout.

Hope this gives you an idea to play with...

6 years ago

Thank u so much @pamtbaau , this is exactly what I want.
Easy to follow your directions.

have a nice day.

Suggested topics

Topic Participants Replies Views Activity
Support · by Water Science, 3 weeks ago
11 152 1 hour ago
Support · by Duc , 17 hours ago
1 42 17 hours ago
Support · by Thomas, 1 week ago
3 115 1 day ago
Support · by Anna, 4 days ago
2 105 2 days ago
Support · by Justin Young, 2 days ago
1 82 2 days ago