Add frontmatter config into twig print function

Hey!

I am trying to make a dynamic way to add images to a list. This is what I am trying to do.

          {% for item in page.header.list %}
      <div class="card">

=== Problem to fix ===

        <img class="card-img-top img-fluid" src="{{ page.media['{{ item.image }}'].url }}" alt="Card image cap">

=== End of problem to fix ===

        <div class="card-block">
          <h4 class="card-title">{% if item.link %}<a href="{{ item.link }}">{% endif %}{{ item.title }}{% if item.link %}</a>{% endif %}</h4>
          <p class="card-text">{{ item.text }}</p>
        </div>
        <ul class="list-group list-group-flush">
        </ul>
      </div>
      {% endfor %}

But this does not work unfortunatly…

Is there a way to do this?

Never mind… It was simpler then i was expecting so I was searching for a complicated answer.

I just removed ‘{{}}’ only to have

{{ page.media[item.image].url }} 

and it works!

I love Grav CMS and the Grav team for their ingenious ideas and amazing work!
Learning more and more and wish to contribute when i have something to contribute other then be active in the forum :slight_smile:

Thank you!!! :smiley:

2 Likes

Drop the {{ }} around item.image :slight_smile:

1 Like