I need a hack that applies custom code to some CMS Collection Pages and not others

I have a CMS Collection… some pages include a video, some don’t. I want to dynamically add Schema to the pages with video only. Is there an “out of the box” solution to do this?

From testing, I either A) add code to all related records, and dynamically change portions (which will produce an error for the pages without video), or B) don’t add this code to any pages.

Similarly, I want to add hreflangs to some pages and not others within the same CMS Collection. As you can see, there are a number of reasons I need a hack.


Hello Evan.

There are indeed a couple of different ways to achieve that. If you have some knowledge of JavaScript, you can go through all collection items, find which ones has a <video> tag as a child, and add your code to those.

Another way would be to add an option field to the CMS, let’s call it ‘type’, give it certain options depending on what you’d like to change (eg. ‘video’, ‘links’, etc…). Then, link that option field to a hidden paragraph element inside the item, and use it directly with JavaScript to access the parent.

The Read-Only link isn’t working so I couldn’t check your website, but the above works for all cases.