Find out if macro or partial is included on the page
I'm looking at loading certain scripts dynamically depending if the page contains partials that are using it, but don't want to include them in the partial itself to avoid duplication. Is there a way on page load to determine if a marco or partial exist as part of the page context?
Adding them to the page is not an option, because there are too many existing pages to update and also would rely too much on someone remembering to add them in.
Generally the page could look like the layout below, but with more components. At the moment all the styles and scripts for the page are loaded in the template in a bundle. I could add them to the each individual partial inline but there are a lot of them (small-pod scss is over 1500 lines) and I don't want to load same scripts multiple times.
Ideally, I would want to know on page load if certain partial is on page, e.g. video-pod, and if it is there, then I would add all relevant scripts to the template.
Is video-pod a documenttype or simply a partialview in the template?
If it is a document type or grid block in the backoffice then you should be able to check if it exists in the page or not, if it is just a partial view in the template then I don't know how you can check that.
Find out if macro or partial is included on the page
I'm looking at loading certain scripts dynamically depending if the page contains partials that are using it, but don't want to include them in the partial itself to avoid duplication. Is there a way on page load to determine if a marco or partial exist as part of the page context?
Thanks
Why not just add them to the base page which includes your partials?
This is what we currently have which adds a lot of unused scripts and styles to every page and affects performance.
I meant add to the page that has the partials not your master template.
Maybe you could provide a basic example of your templates
Adding them to the page is not an option, because there are too many existing pages to update and also would rely too much on someone remembering to add them in.
Generally the page could look like the layout below, but with more components. At the moment all the styles and scripts for the page are loaded in the template in a bundle. I could add them to the each individual partial inline but there are a lot of them (small-pod scss is over 1500 lines) and I don't want to load same scripts multiple times.
Ideally, I would want to know on page load if certain partial is on page, e.g. video-pod, and if it is there, then I would add all relevant scripts to the template.
Is video-pod a documenttype or simply a partialview in the template?
If it is a document type or grid block in the backoffice then you should be able to check if it exists in the page or not, if it is just a partial view in the template then I don't know how you can check that.
Its not. Oh well, it was worth checking out. Thanks
is working on a reply...