Conditionals & loops on html template

I want to create a workflow who recieve a JSON params, render html template and convert it to PDF. I can use variables on html template but. Can i use conditions as if/else or loops as for/foreach/while?

I want to create a workflow who recieve a JSON params, render html template and convert it to PDF. I can use variables on html template but. Can i use conditions as if/else or loops as for/foreach/while

HTML template uses handlebars or something like this?

<div class="entry">
{{#if author}}
<h1>{{firstName}} {{lastName}}</h1>
{{else}}
<h1>Unknown Author</h1>
{{/if}}
</div>
<ul class="people_list">
  {{#each people}}
    <li>{{this}}</li>
  {{/each}}
</ul>

Hi @50l3r :wave: Welcome to the community :tada:

In the actual template itself, no - while you can use expressions to pull in data, you wouldn’t be able to do a full loop. JS in <script> tags is included for templating, but that won’t be executed in n8n.

You could try to use a code node here that looks for if this content exists, and then use that in the HTML template since expressions do exist :slight_smile:

I’d also suggest heading over to our feature request section of our forums and creating a thread there, as our product team reads those forums regularly!

1 Like

Much thanks @EmeraldHerald I’l try alternatives. Maybe a script who render html with ejs or something.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.