Conditionally load a Tangible Styles sheet?

Hi there, for my WordPress theme, I load a brand-specific stylesheet that customises the look and feel of the website.

Currently, I have a solution for this, which involves conditionally loading a Tangible Template and its CSS using the Document Head location based on a custom field.

<Template name="{Field name=sim_brand_styles_template from=options}" />

This seems to work fine, but is it possible to conditionally load a Tangible Styles sheet or will this feature be added in future?

Thanks,
Phil.

I’m pretty sure this is already built in if you create a “style” instead of a “template” post. There’s a location option that allows you to set where you want your style to load.

Edit: rereading your post, I imagine you’re already aware of this feature. I guess whether this will work for you depends on what you mean by “conditionally load.” If you mean you want to select which page the stylesheet loads on, this will work for you, but if you want complex conditional logic like only loading the stylesheet if a certain field matches a certain value, then this wouldn’t work and your approach would probably be the way to go. I’m not sure if it would make sense to create a conditional logic interface around this location since it would probably be tough to get this as flexible as using an If tag in a template. We’re going to be building a UI for conditional logic eventually so maybe this could work, but I imagine there will always be an upper limit to how flexible that could be. For example, if you need to create a loop to get some other value and then run some conditional logic based on that, a template would be the way to go.

Overall, I can see a value in consolidating the different L&L post types and building out the UI so I’ll keep this suggestion in mind once we get there.

1 Like

I’ve always thought it would be nice to allow any of our post types (template, block, style, script) to be pulled in with a Template tag, though loading styles and scripts inline, scattered about pages may not be optimal :sweat_smile:

2 Likes

I was not super clear in my original post.

I have a theme running across multiple websites so I just need to call a different style sheet depending on the domain.

The solution I have working calls a brand template and its styles based on an ACF field with the template name.

A nice to have feature might be too activate a Tangible Styles sheet using template logic or just improve the Styles ‘route’ location so it is domain aware.

Probably that last option is the simplest. :slightly_smiling_face:

2 Likes

Here is a mock-up of how the Route location could be improved:

2 Likes