Open jmshey90 opened 1 year ago
It's better not to mix atom and particle logic in the same file. But if you really want to, then you can try to do this in a particle:
{% set is_my_script = false %}
{% for atom in gantry.config.page.head.atoms if atom.type == 'assets' %}
{% set attr = atom.attributes %}
{% if attr.enabled %}
{% for script in attr.javascript if script.location == 'gantry-assets://js/eryc-datepicker.js' %}
{% set is_my_script = true %}
{% endfor %}
{% endif %}
{% endfor %}
{% if not is_my_script %}
{% spaceless %}
{% do gantry.document.addScript(url('gantry-assets://js/eryc-datepicker.js'), 1, 'footer') %}
{% endspaceless %}
{% endif %}
Just an example. Perhaps there is a more elegant solution.
I'm using the CSS/JS atom to add a script:
- { location: 'gantry-assets://js/eryc-datepicker.js', inline: '', in_footer: '1', extra: { }, priority: '1', contains, name: 'Date Picker' }
I also have a particle which loads it:
However, I get the script loaded twice. My understanding is that Gantry would only ever add one instance of the same script?