So I've been using React for a while now, but I need to use ejs for my current project. What I want to do is to return various radio elements. I tried doing it with this code:
<% const renderRadios = (value, name) => (
`<label for="eventRate${value}" class="col-sm-2 col-form-label">1</label>
<input type="radio" id="eventRate${value}" class="form-control" name="${name}" value="${value}" required>`
) %>
<% for (let i = 1; i <= 5; i++) { %>
<%= renderRadios(i, 'eventRate'); %>
<% } %>
I think this kind of explains what I was going for. This is what this code is doing though:

And I mean it does what I told it to do. But I would like the browser to parse it as HTML. Any ideas how to render these elements as HTML?
This is how I made it
<% const renderRadios = (value, name) => { %>
<div style="display: block;">
<input type="radio" id="<%= name %><%= value %>" class=""
name="<%= name %>" value="<%= value %>" required/>
<label for="<%= name %><%= value %>" class="">
<%= value %>
</label>
</div>
<% } %>
<% for (let i = 1; i <= 5; i++) { %>
<%= renderRadios(i, 'eventRate'); %>
<% } %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With