Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anna 4 posts 84 karma points
    Feb 17, 2021 @ 14:16
    Anna
    0

    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

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Feb 18, 2021 @ 18:52
    Huw Reddick
    0

    Why not just add them to the base page which includes your partials?

  • Anna 4 posts 84 karma points
    Feb 19, 2021 @ 09:00
    Anna
    0

    This is what we currently have which adds a lot of unused scripts and styles to every page and affects performance.

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Feb 19, 2021 @ 17:42
    Huw Reddick
    0

    I meant add to the page that has the partials not your master template.

    Maybe you could provide a basic example of your templates

  • Anna 4 posts 84 karma points
    Feb 22, 2021 @ 09:28
    Anna
    0

    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.

    enter image description here

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Feb 22, 2021 @ 10:19
    Huw Reddick
    100

    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.

  • Anna 4 posts 84 karma points
    Mar 02, 2021 @ 09:22
    Anna
    0

    Its not. Oh well, it was worth checking out. Thanks

Please Sign in or register to post replies

Write your reply to:

Draft