1

I have created a field named inlineCss, which i'm using to set a pageCss variable. However, when no CSS is added to the entry, the {% includeCss pageCss %} is still adding a style tag in the head, albeit empty.

{% set pageCss %}
    {{ entry.inlineCss }}
{% endset %}

{% includeCss pageCss %}

Is there a way to only show the style tag if the pageCss variable is not empty?

I've tried checking for is defined and not null but it just keeps outputting the empty style tag.

3

It looks like you should be able to wrap it in an if statement like this...

{% set pageCss %}
    {{ entry.inlineCss }}
{% endset %}

{% if pageCss != ''  %}
    {% includeCss pageCss %}
{% endif %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.