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.

Archive

How does one work with themes?

Started by Muut Archive 9 years ago · 1 replies · 393 views
9 years ago

I've read a lot in the documentation, but I really don't get how certain things from a theme are supposed to be referenced, when you write a text in markdown, where exactly it goes. I've been trying to figure out exactly what I should be doing so I can properly use a different theme and write my content in the right place, but it just seems rather complicated.

9 years ago

Hello,

The content of your markdown file will go in the block :

TWIG
{% block content %},{% endblock %}
--- 
Of the corresponding `twig` file.

I'll give you an example of my own, 
I have a modular page `modular.html.twig`

{% extends 'partials/base.html.twig' %}
{% block content %}
{{ page.content }}
{% for module in page.collection() %}
{{ module.content }}
{% endfor %}
{% endblock %}

TWIG
As you can see, the contant of a page `modular.md` will go in the `{% block content %},{% endblock %}`

My `modular.md` looks like that :

title: 'Page modulaire'
menu: 'Contenu'
onpage_menu: true
content:
items: '@self.modular'
order:
by: default
dir: asc
custom:

  • _texte
  • _texte2
    TXT
    It will call two sub-modular in subfolder `_texte` and `_texte2`
    In those subfolder I have a markdown file `texte.md`
    

    article:

    • titre: h1 de l'article
      titre2: h2 de l'article
      position: droite
      photo:
    • image: section-01.jpg
      legende: Balise alt de l'image
      TXT
      
      

      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vel cupiditate, laudantium ipsum nesciunt! Enim exercitationem epellendus accusantium minus obcaecati nisi, consectetur temporibus modi et aliquam. Dicta sunt beatae, illum sit!


The corresponding twig file texte.html.twig looks like that :

TWIG
<section class="row contenu">
    {% for art in page.header.article %}
        {% if art.position|lower|contains('droite') or art.position|lower|contains('right') %}
            <article class="col-xs-12 col-sm-6 right">
        {% else %}
            <article class="col-xs-12 col-sm-6">
        {% endif %}
                <h1 class="titre1">{{ art.titre }}</h1>
                {% if art.titre2 %}
                    <h2 class="titre2 color2">{{ art.titre2 }}</h2>
                {% endif %}
                {{ page.content }}
            </article>
        {% endfor %}
        {% for img in page.header.photo %}
            <figure class="col-xs-12 col-sm-6">
                <img src="{{page.media[img.image].url}}" alt="{{ img.legende }}" />
            </figure>
    {% endfor %}
</section>

In this template you can see {{ page.content }}, this is where the content of the texte.md will go.

I'm not a specialist in templating, but I hope that it will help ;)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1318 9 years ago
Archive · by Muut Archive, 9 years ago
2 915 9 years ago
Archive · by Muut Archive, 9 years ago
2 4044 9 years ago
Archive · by Muut Archive, 9 years ago
1 2920 9 years ago
Archive · by Muut Archive, 9 years ago
3 1104 9 years ago