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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Loop data from YAML multilingual

Started by Zoltán Kárpáti 8 years ago · 3 replies · 676 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 Jerry Hunt, 4 days ago
2 104 18 hours ago
General · by pamtbaau, 23 hours ago
1 88 22 hours ago
General · by Andy Miller, 1 day ago
0 53 1 day ago
General · by Marcel, 12 months ago
6 381 5 days ago
General · by Duc , 6 days ago
3 69 6 days ago