Alpine code on a template that is injected by javascript breaks when a plugin is installed that also uses alpine. #4688
Unanswered
BramMortier
asked this question in
5. Bugs
Replies: 1 comment 5 replies
-
|
I don't see what would cause an issue here. When you say it's "broken" what is broken? |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This "bug" or lack of knowledge by me has had me running against a wall for days. I build mostly Craft CMS websites (twig based templating) and use AlpineJS for interactivity. I love how easy it makes everything!
Recently I've also dabbled in building custom Craft CMS plugins where I was again hoping to use AlpineJS for the javascript stuff. First issue I had to solve was how Alpine reacts to multiple instances on the same page. A quick google search gave me this issue on the Alpine repository itself
#3016
This solved the issue for me with the downside of losing shorthands and the Alpine global window object. Not bad especially since plugins really don't get as complex as websites. It worked fine until i installed my plugin on a site that has javascript filters. Everytime a filter is clicked this alpine method is executed. It fetches a twig template that has two view modes list and grid.
{% set class = class|default("") %} {% set attributes = attributes|default({}) %} {% set projects = projects|default([]) %} <div class="c-project-results {{ class }}" {{ attr(attributes) }}> <div class="c-project-results-info"> <p class="typo-body-md">{{ projects|length }} Resultaten</p> {% include "_components/projectResultsViewControls" %} </div> {% if projects|length %} <div x-show="view === 'grid'" class="c-project-results-grid"> {% for project in projects %} {% set image = project.featuredImageField.one|default("") %} {% set title = project.title|default("") %} {% set dateOfCompletion = project.dateOfCompletionField|default("") %} {% set services = project.servicesProvidedField|default([]) %} {% set description = project.descriptionField|default("") %} {% set url = project.url|default("") %} {% include "_components/projectCard" with { image, title, dateOfCompletion, services, description, url } only %} {% endfor %} </div> <ul x-show="view === 'list'" class="c-project-results-list"> {% for project in projects %} {% set image = project.featuredImageField.one|default("") %} {% set title = project.title|default("") %} {% set dateOfCompletion = project.dateOfCompletionField|default("") %} {% set services = project.servicesProvidedField|default([]) %} {% set description = project.descriptionField|default("") %} {% set url = project.url|default("") %} {% include "_components/projectListItem" with { image, title, dateOfCompletion, services, description, url } only %} {% endfor %} </ul> {% endif %} </div>The state of this injected template is manages outside of itself
For some reason this breaks the functionality only if the plugin is installed?
this is the project alpine initialisation
and this is the initalisation within the plugin.
Do you see any reason why this would break stuff? I'm guessing alpine gets confused on which component the injected template should listen to but I get no errors in the console... Would love to get some help on this one!
Beta Was this translation helpful? Give feedback.
All reactions