Dynamically creating component layouts in JavaScript
Reading time: 1 Minute
One function in a new file is all you need#
Check this out!
// BlockListItem.js
/// HTML Output
///<li class="block-list-item" data-controller="block-list-item" data-block-list-item-url-value="{{url}}">
// <span>{{url}}</span>
// <button class="primary" data-action="block-list-item#delete">Remove</button>
// </li>
...and just like that, you have a component layout that can be reused across multiple vanilla JS code files!
Reusing the layout across different JavaScript files.#
In another JavaScript file, you could can use this component layout like this:
;
// Somewhere down in the code, we'll create the HTML layout for the component:
;
;