This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Coding Crafter
Coding Crafter

How would one go about creating a dynamic class?

Such as?

{# On the homepage #}
<body class="myClass-home">
...
</body>

{# On the about page #}
<body class="myClass-about">
...
</body>

I tried to use a filter like:

<body class="myClass-{{ this.page.title }}">
...
</body>

The twig markup spit it out, but the problem arises that "About Me" for the title would output:

<body class="myClass-About Me">
...
</body>

What would be a better solution for this to get it formatted nicely?

daftspunky
daftspunky

Hi Coding Crafter!

{{ this.page.id }} can be used for this.

I hope this helps.

Coding Crafter
Coding Crafter

daftspunky said:

Hi Coding Crafter!

{{ this.page.id }} can be used for this.

I hope this helps.

an elegant solution! Thank you.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.