Published on Aug 26, 2020

Adding Custom Attributes Conditionally in Oxygen

David Browne

There will be situations where we only want attributes to be applied to elements conditionally. Maybe inside of a repeater, but only specific posts. Maybe added to a header, but only when we're on specific pages, etc.

In this members-only we'll look at how we can control when custom attributes are added across our templates & pages of our site based on some conditions.

One main use case for this is when using attributes for JS libraries where the JS is searching the page for the elements which have the attributes in order to apply a specific effect or to retrieve some data. Instead of having to build multiple versions of elements, some with attributes and some without, we can instead add the attributes conditionally.

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $499 one-time).

Already a member? Log in below or here.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right