Adding Javascript to Template Parts
-
I’m working on my header in the template parts. Everything works as intended until I try to add alpine.js inline to toggle my menu. For example if I were to add:
<!-- wp:group {"className":"hdr__inner","layout":{"type":"default"}} --> <div class="wp-block-group hdr__inner" x-data="{ menuOpen: true }"> <button @click="menuOpen = !menuOpen" >toggle</button> <!-- wp:group {"className":"hdr__nav-wrap","layout":{"type":"default"}} --> <div class="wp-block-group hdr__nav-wrap" x-show="menuOpen" :class="menuOpen ? 'hdr-open' : 'hdr-close';"> Area to toggle </div> <!-- /wp:group --> </div> <!-- /wp:group -->
Everything will work in the browser, I receive a “This block contains unexpected or invalid content.” in the editor.
Is there a way around this that will allow me to add alpine or data attributes to my template parts?
I also ran into the same issue when I was adding inline SVGs
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Adding Javascript to Template Parts’ is closed to new replies.