Closed matuzalemsteles closed 6 years ago
We need to define a convention for this. My suggestion would be to make components accept a param named "dataAttributes" containing a map.
{call Component.render}
{param dataAttributes: [
'id': '23',
'myAttribute': 'myValue',
....
] /}
...
{/call}
and in the component use it just like elementClasses
:
{let $attributes kind="attributes"}
{if $dataAttributes}
{foreach $attributeKey in keys($dataAttributes)}
data-{$attributeKey}="{$dataAttributes[$attributeKey]}"
{/foreach}
{/if}
{if $elementClasses}
{$elementClasses}
{/if}
...
{/let}
Hey @carloslancha, Sounds good to me, do you think we should use in more other components?
@matuzalemsteles maybe is a good idea to add elementClasses
, id
and dataAttributes
to all components by default and add it as a good practice to the guidelines.
@carloslancha I like this idea, I think we can do it.
Hey @carloslancha, The SoyToIncrementalDomSrcCompiler
does not support using variables to transform into attributes. There is a question about this https://github.com/google/closure-templates/issues/112.
Hey @matuzalemsteles
@jbalsas had an idea about how to handle this, I'm working on it!
In JSP some users need to pass attributes to their components and one way was to use the
data
parameter like HashMap, Use cases like when you want a link not to use the SPA, passingdata-senna-off
.