Closed BernaLang closed 4 months ago
I'm not seeing this behavior; can you provide a reproducible sample? Nunjucks doesn't read html (it's just treated as string output) so there's nothing here that should cause a special case.
My gut feeling is, you're running stale cached templates, or there's something else going on there.
[devoidfury@mini devcli]$ node
Welcome to Node.js v21.2.0.
Type ".help" for more information.
> const nunjucks = require('nunjucks')
undefined
> const template = `<div>
... <div>
... <input
... type="text"
... value="{{validation.maxlength}}"
... {% if validation.required %} required {% endif %}
... {% if validation.maxlength %} maxlength="{{validation.maxlength}}" {% endif %}
... />
... <div class="message">
... {% if validation.maxlength %} Works! {% endif %}
... </div>
... </div>
... </div>`
undefined
> console.log(nunjucks.renderString(template, { validation: { required: true, maxlength: 5 } }))
<div>
<div>
<input
type="text"
value="5"
required
maxlength="5"
/>
<div class="message">
Works!
</div>
</div>
</div>
After some more extensive debugging we figured it out. Turns out it was our gulp configuration that was altering that specific condition when compiling the templates. Will close the issue, thanks for the response!
I'm trying to render a dynamic input using nunjucks latest version (3.2.4). I have this template:
And when I render:
nunjucks.render(template, { validation: { required: true, maxlength: 5 } })
I get a really weird behaviour. The input renders with the properties
value=5
andrequired
but it doesn't render with themaxlength
property. On top of that, the message "Works!" also shows correctly. I've also tried changing the if a bit (like returning a simpledisabled
property) but it still won't work.Could this be a possible issue on nunjucks or am I missing something here?