Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering template strings in RiotJS

Tags:

riot.js

I have a template string "<a onclick={ parent.foo }>Link</a>". I want pass it to other tag and than render it correctly. I added short example of my code. It doesn't work, just try to show what I need.

<child-tag>
    <div>{ opts.data }</div>
</child-tag>

<parent-tag>
    <child-tag data={ html }></child-tag>
    
    <script>
    this.html = "<a onclick={ parent.foo }>Link</a>";

    foo() {
        console.log("Hello");
    }
    </script>
</parent-tag>
like image 807
Artkik Avatar asked Sep 09 '26 09:09

Artkik


1 Answers

Riot will escape the html where you have { opts.data }. You can use the <raw> tag as described in the riot documentation. But it may be best to rewrite the code as such.

https://jsfiddle.net/nnyc688e/1/

<child-tag>
  <yield/>
</child-tag>

<parent-tag>
    <child-tag> <a onclick={ parent.foo }>Link</a> </child-tag>

    foo() {
      console.log("Hello");
    }
</parent-tag>

That's easier to understand too.

like image 82
Ryan Allred Avatar answered Sep 13 '26 06:09

Ryan Allred



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!