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

Twig does not output data

Started by Muut Archive 10 years ago · 3 replies · 280 views
10 years ago

i have had this problem multiple times ...

file: the-huntsman-the-ice-queen-3d/movie.md

YAML
title: 'The Huntsman & The Ice Queen (3D)'
age_limit: 12
length: 114
visible: true
release: '2016-04-07'

the file tree looks like:

TXT
pages
   start.md
   movies
      movie.md

file: start.md

TWIG
{% extends 'partials/base.html.twig' %}
{% block content %}
  {% set all_movies = page.find('/movies').collection %}
  <section class="movies"> 
    {% for each_movie in all_movies %}
      {% set each_movie_date = each_movie.header.release|date("Y") %}
      <article class="movie">
        <header>{{ each_movie.title }}</header>
        <aside>
          <span class="age_limit">Ab {{ each_movie.header.age_limit }} Jahren</span>
          <span class="length">{{ each_movie.header.length }} Minuten</span>
        </aside>
        <main>{{ each_movie.content }}</main>
        <footer>{{ each_movie_date }}</footer>
      </article>
    {% endfor %}
  </section>
{% endblock %}

twig does not render the information in the title and content variable properly. where is my mistake ?

10 years ago

Are you sure you are getting the collection properly? The best way to debug these types of things is to use the {{ dump(var) }} command and look in the debug bar to see what the values are.

Start with all_movies var to ensure you find the collection, if you are getting that, try dumping each_movie, then try each_movie.title etc.

10 years ago

Thanks, now everything works just fine!!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1361 9 years ago
Archive · by Muut Archive, 9 years ago
2 939 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2958 9 years ago
Archive · by Muut Archive, 9 years ago
3 1123 9 years ago