3

I can't seem to figure out how to pass my variable into the class, ID, or data attributes on my custom element.

<ub-item class="item cssV2 { opts.status }" id="{ opts.id }" data-link="{ opts.url }">

opts.status, opts.id, and opts.url all work if I pass them in an element like <p>, but how do I pass the variable into the attributes? The HTML output includes them as strings.

bholtbholt
  • 11,281
  • 6
  • 22
  • 32

2 Answers2

3

Variables which will be used in tags should be created using this:

<mytag>
 <p class="{ myclass: show }" id="{ myid }" data-link="{ mydata }">Example</p>

 <script>
   this.mydata = 'foo'
   this.myid = 'bar'
   this.show = true
 </script>
</mytag>

This will be rendered as:

 <mytag>
  <p class="myclass" id="bar" data-link="foo">Example</p>
 </mytag>
peckles
  • 66
  • 2
  • 7
0

My guess, since I' afraid no further informations were provided.

Maybe you just need to assign the opts to self/this to make them available to the view.

self = this
self.opts = opts

And if the parameters are chaning:

self.on('update', function(){
  self.opts = opts
})
Federico Elles
  • 4,659
  • 7
  • 27
  • 35