Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Scoped CSS?

Started by Muut Archive 9 years ago · 3 replies · 433 views
9 years ago

How can I provide css just to one type of page?!??

9 years ago
TWIG
{% if page.url == base_url %}
  <link rel="stylesheet" href="{{ theme_url }}/css/welcome.css">
{% endif %}

this works. but is there another way of conditionally rendering a stylesheet just for a welcome page?

9 years ago

You could match the template or slug of the page you'd want to add the specific style for, e.g:

TWIG

{# for matching slug #}
{% if page.slug == 'welcome' %}
   <link rel="stylesheet" href="{{ theme_url }}/css/welcome.css">
{% endif %}

{# for matching template #}
{% if page.template == 'welcome' %}
   <link rel="stylesheet" href="{{ theme_url }}/css/welcome.css">
{% endif %}
---

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1334 9 years ago
Archive · by Muut Archive, 9 years ago
2 925 9 years ago
Archive · by Muut Archive, 9 years ago
2 4056 9 years ago
Archive · by Muut Archive, 9 years ago
1 2939 9 years ago
Archive · by Muut Archive, 9 years ago
3 1112 9 years ago