cbHasLayout? can this be easily produced?

I’m looking to inject some javascript if a particular layout is used on a page. Is there an equivalent snippet, similar to cbHasField, but for layouts? How difficult would it be to create this snippet?

Hi Mike,

A snippet like that is not available currently (unless someone else wrote one), but I’ve logged it in our tracker as #453 and will let you know if we add it.

If you’re comfortable with PHP, you could grab the raw content from $resource->getProperty('content', 'contentblocks') and iterate over that to see if it has the layout you need. If you use nested layouts, or repeaters with layout fields, you’ll need to recursively search for those as well.

Note that in ContentBlocks 2, we’re going to change the way content is stored, so that approach wouldn’t work there. We don’t have an ETA for that release yet though, and it’ll probably take some time until we get that out, but just so you know :wink: