This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

josh70520
josh70520

I'm looking for the ability to put something in the scripts placeholder, but only if it's not been put there before.

Case point for a carousel partial that might be used multiple times on a page:

<div class="glider">
    ...
</div>

{% put scripts %}
    {% once %}
        <script src="https://cdn.jsdelivr.net/npm/glider-js@1/glider.min.js"></script>

        <script>
            window.addEventListener('load', function(){
                new Glider(document.querySelector('.glider'), {});
            });    
        </script>
    {% endonce %}
{% endput %}
daftspunky
daftspunky

There is no feature like this, but the addJs/addCs functions do eliminate duplicate scripts from being added programmatically. There are no promises but this could work

{% do this.controller.addJs('https://cdn.jsdelivr.net/npm/glider-js@1/glider.min.js') %}
josh70520
josh70520

Fair play - thank you - I'll try it out

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.