How can I check with TypoScript if a NodeType is used on the current page?

Hi,

I’m wondering how I can check if a nodetype is added to the current page.

I tried several things, what made most sense but didn’t work for me was this:

@if.elementExists = ${q(node).has('[instanceof Vendor.SiteName:NodeType]') == true}

I want to use this to determine if I have to add a JS/CSS file to the current page

Thank you!

Response from Christian Müller to this question:

I think there is currently no way of doing this in a really good way
find().count() > 0 would be the best direction
but then you need to do the find already inside the content collection(s) otherwise you will look at subpages as well

Hi Alexander,

got this tip from Aske a longer time ago, don’t know if it still works:
@if.hasNodeType = ${q(node).find(’[instanceof Vendor.SiteName:NodeType]’).is()}

Greets Kerstin

Hi Kerstin,

thank you very much! This works perfekt!

Nice one!
Though it wouldn’t work if you render some nodes from other documentNodes (e.g. shared footer or smth).

But in general it’s a rare case when splitting up your CSS & JS bundles would be justified, it may only hurt performance with extra requests.