some text Now I want to add" /> some text Now I want to add" /> some text Now I want to add"/>

How do I add another attribute to style in a view file (macro) in apostrophe CMS?

29 Views Asked by At

So I have a code that's like this:

  <a {% if options.style %} style="{{ options.style }}" {% endif %} href="{{ path }}">some text</a>

Now I want to add an additional property tp style, say for padding that's coming from another attribute. How can I do that?

I tried this way but it didn't work.

<a {% if options.style %} style=" {{ {...options.style, padding: {{data.linkPadding}}} }}" {% endif %}>some Text</a>
 
  
1

There are 1 best solutions below

4
ABGR On BEST ANSWER

Since this is nunjucks (it doesn't work like just extending javascript object as I was trying to do), the way to do this would be following:

<a
     {% if options.style %} 
        style="{{ options.style }}; 
                 padding: {{data.linkPadding}}"
     {% endif %}>some Text</a>

This was answered by Bob on apostrophe Discord community.