Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Adding inline CSS to the header

Started by Muut Archive 11 years ago · 4 replies · 835 views
11 years ago

Hi,
is it possible to add inline CSS to the header from within a modular template?

11 years ago

Have you tried it? I think it should work, but you might need to disable the page cache for that page.

11 years ago

Yes I tried it, but most likely I did something wrong because it didn't work.
I used

TWIG
{% do assets.addInlineCss('h1{color: red;}') %}

in the modular template but there was no output in the header, even with disabled cache.

Would you please show me how to do it?

11 years ago

Can you paste the whole modular template?

10 years ago

This is the wohle content of the modular template. The the content of the addInlineCss command is just for testing purpose.

TWIG

{% do assets.addInlineCss('.text-box{color:red !important;}')%}

<article class="text-box {{ header.boxStyle|join(' ') }}"
         style="
            {% include 'partials/bg-image.html.twig' with {'images':page.media.images} %}
         "        
        >
    {{ header.buttonLinks }}
    <div class="inner {{ header.boxInnerStyle }}">
        {{ content }}
        {% if header.linkBox %}
            {% include 'partials/linkbox.html.twig' with {'linkBox':header.linkBox} %}
        {% endif %}
    </div>
    {% if header.triggerCaption is not empty %}
        <div class="trigger trigger-button" data-dir="next"><span>{{ header.triggerCaption }}</span></div>
    {% endif %}
    {% if header.showStopper %}
        {% include 'partials/stopper.html.twig' %}
    {% endif %} 
    {% if header.perkText %}
        <div class="perk aright">
            {{ header.perkText }}
        </div>
    {% endif %}
</article>
---

Suggested topics

Topic Participants Replies Views Activity
Archive · by Muut Archive, 10 years ago
1 676 1 week ago
Archive · by Deleted User, 9 years ago
0 3043 9 years ago
Archive · by Muut Archive, 9 years ago
2 1983 9 years ago
Archive · by Muut Archive, 9 years ago
2 5338 9 years ago
Archive · by Muut Archive, 9 years ago
1 4135 9 years ago