harttle / liquidjs

A simple, expressive, safe and Shopify compatible template engine in pure JavaScript.
https://liquidjs.com
MIT License
1.54k stars 237 forks source link

Javascript function is not defined - Error #382

Closed pavangayakwad closed 3 years ago

pavangayakwad commented 3 years ago

Using it inside the angular component allowing users to write their own html with javascript functions.

The template to be rendered.

<script type="text/javascript">
function fnDone(v){
alert(v);
}
</script>

{% for d in data %}
<div>
{{d.title}}
<button onclick="fnDone(d.title)">{{d.title}}</button>
</div>
{% endfor %}

In the backend, Initialized the engine,

_UIengine = new Liquid({
    cache: true
  });

...and rendered the template with the data

let data = {/* received from API */ };

this._UIengine.parseAndRender(this._template, data)
.then(html => this.assignRenderedHtml(html));

The HTML page is coming up nicely however when I click on the button, receiving the fnDone is not defined error.

image

Here is the rendered HTML image

What am I doing wrong here? Please assist.

harttle commented 3 years ago

I believe it should be onclick="()=>fnDone(d.title)"