Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Loop data from YAML multilingual

Started by Zoltán Kárpáti 8 years ago · 3 replies · 1045 views
8 years ago

Hi!

I am working on my first Grav site and I am preparing a chronology in multilingual mode. Here is my html skeleton:

HTML
    <div class="timeline-item" data-text="name">
      <div class="timeline__content">{{ page.find('/images/gallery').media['img'].html('', '', 'timeline__img') }}
        <h2 class="timeline__content-title grey-text text-lighten-3">date</h2>
        <p class="timeline__content-desc grey-text text-lighten-1">desc</p>
      </div>
    </div>

How can I load data with a loop method? I think md is not suitable for this, but should I use YAML file with the following in multilingual? Thank you for all your help!

YAML
  history: 
    en:
      -
        name: 'About EN'
        img: '1.jpg'
        date: '1886'
        desc: 'Lorem ipsum... EN'
      -
        name: 'About2 EN'
        img: '2.jpg'
        date: '1925'
        desc: 'Lorem ipsum...2 EN'
    hu:
      -
        name: 'About HU'
        img: '1.jpg'
        date: '1886'
        desc: 'Lorem ipsum... HU'
      -
        name: 'About2 HU'
        img: '2.jpg'
        date: '1925'
        desc: 'Lorem ipsum...2 HU'
8 years ago

Have you had a look at the documentation about MetaFiles? These are yaml files that can contain any meta data you would like to add to an image.

8 years ago

Yes, taking your yaml example, you could do something like the following in Twig:

TWIG
{% set language = grav.language.getlanguage %}
{% set image = page.find('/images').media.images['myimage.jpg'] %}
{% for history in image.meta.history[language] %}
    {{ history.name }}
{% endfor %}
last edited 09/05/18 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
General · by themetman, 24 hours ago
2 41 17 hours ago
General · by Hanns Mattes, 1 week ago
0 121 1 week ago
General · by Karmalakas, 1 week ago
2 185 1 week ago
General · by Hanns Mattes, 3 weeks ago
0 235 3 weeks ago
General · by Dima, 4 weeks ago
1 211 4 weeks ago