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

Modular page can't get custom variables from base template

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

Sometimes I get this annoying problem and I have no idea what causes it.

Form the base template file (partials/base.html.twig), I set the global variable for site and theme's configuration.

TWIG
{% set theme_config = attribute(config.themes, config.system.pages.theme) %}
<!DOCTYPE html>
<html lang="{{ grav.language.getLanguage ?: 'en' }}">
    <head>
        {% include "partials/head.html.twig" %}
    </head>
    <body>
        {% block content %},{% endblock %}
    </body>
</html>

Here is my modular.html.twig:

TWIG
{% extends 'partials/base.html.twig' %}

{% block content %}
    {% for module in page.collection() %}
        {# theme_config is still available here #}
        {{ module.content }}
    {% endfor %}
{% endblock %}

In my modular page themeconfig variable is null. However I still can get config variable of Grav. This problem sometimes happens, sometimes not. My only solution right now is re-set themeconfig variable in each modular page:

TWIG
{% set theme_config = attribute(config.themes, config.system.pages.theme) %}

If you have any idea of why this happens, please let me know. Thanks!

9 years ago

Hmm, it seems in modular page the global variable "pages" is not accessible too. I need to use page.parent.parent.children instead of pages.children.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1282 9 years ago
Archive · by Muut Archive, 9 years ago
2 889 9 years ago
Archive · by Muut Archive, 9 years ago
2 4019 9 years ago
Archive · by Muut Archive, 9 years ago
1 2894 9 years ago
Archive · by Muut Archive, 9 years ago
3 1078 9 years ago