Question on calling body_classes in Twig

In the Gantry5 modular.html.twig template it contain the following code:

{% block content %}
{{ page.content|raw }}
{% for module in page.collection() %}
    <div id="{{ macro.pageLinkName(module.menu) }}">
    {{ module.content|raw }}
{% endfor %}
{% endblock %}

I want to modify it so it will use the body_classes tag on a modular page. In some themes this seems to work automatically like in the bootstrap4 theme. The code is almost identical.

{% block content %}
{{ page.content|raw }}

{% for module in page.collection() %}
    <div class="modular-anchor" id="{{ macro.pageLinkName(module.menu) }}"></div>
    {{ module.content|raw }}
{% endfor %}
{% endblock %}

I thought changing the Gantry5 template to use the following would work but it refuses to recognize the page.header.body_classes tag.

<div class="{{ page.header.body_classes }}" id="{{ macro.pageLinkName(module.menu) }}"></div>

Is there a different method to adding the body_classes tag to the modular templates? If I manually add class=“myClsss” instead of the body_classess tag it works.

Thanks.

@tom0360, Maybe I’m just confused, but you show the Gantry template to be:

{% for module in page.collection() %}
    <div id="{{ macro.pageLinkName(module.menu) }}">
    {{ module.content|raw }}
{% endfor %}

and you changed the code inside the loop to:

<div class="{{ page.header.body_classes }}" id="{{ macro.pageLinkName(module.menu) }}"></div>

Correct?

If so, shouldn’t it be referencing module instead of page inside the loop?

<div class="{{ module.header.body_classes }}" id="{{ macro.pageLinkName(module.menu) }}"></div>

Else if your real code is correct, are you sure the frontmatter of the module does indeed contain a value for body_classes. Did you do a dump of module.header to see if body_classes does exist and does have a value?

@pamtbaau,

You are correct. I am just winging it and am not familiar with actually works. I thought I had used the page.header.body_classes on another modular template when I had tried this before but I went and looked at the theme and it is using Bootstrap4 which means it was already working so my changes probably did nothing. lol

Thank you for the help : )

@tom0360, Uhh not sure if I understand what you are saying… Has your problem been fixed or not?

If it has been fixed. please tick the ‘solution’ checkbox. Yes, that’s the one next to the ‘thank you’ aka ‘like’ icon

@pamtbaau,

Sorry, I was testing it out. Yes, it does appear to work correctly now, Thank you.