posthtml / posthtml-modules

Modules Plugin
MIT License
84 stars 11 forks source link

[feat] add attribute/value to locals #76

Closed cossssmin closed 3 years ago

cossssmin commented 3 years ago

Would be awesome if we could take attributes on the <module> tag and pass them into the module's locals.

Of course, this would need to skip the <module>, href="" and locals="" attributes.

Define module.html

<div class="{{ class }}" id="{{ id }}" style="{{ style }}">
  <content></content>
</div>

Use it

<module 
    href="module.html" 
    class="text-center uppercase" 
    id="example"
    style="display: flex; gap: 2;"
>
  Module content
</module>

Result

Module's locals would be:

{
  class: 'text-center uppercase',
  id: 'example'
}

Compiled HTML would be:


<div class="text-center uppercase" id="example" style="display: flex; gap: 2;">
  Module content
</div>