Skip to content

Conditionally setting a variable voids the value when the condition path is not taken #108

@chriskirknielsen

Description

@chriskirknielsen

Hello, and sorry for the potentially confusing title.

I am using Vento via eleventy-plugin-vento for Eleventy, but have managed to replicate the issue in the Vento playground. If a value already exists (in my case, from a template file or a global data value), if I try to overwrite it conditionally, without an else clause, the value is voided/null/empty if the condition is falsy.

{{> url = 'abc' }}
{{ if path }}{{ set url = path }}{{ /if }}
My url value is: {{ url }}

With the example above, if my global data has a url variable (simulated with the first line of JS), but no path variable, the if block should be skipped. However, this produces an empty value. If I remove the if line, the url value is printed as expected.

I don't know exactly how data is fed in the plugin but given I get the same behaviour with just these three lines with Vento in the playground, I would imagine the same underlying issue occurs.

Similarly, if I run the following code with the same conditions (url truthy, path falsy), the variable returns null:

{{ set url = url || path || null }}

I am working around it for now by declaring new variables, but would love for the standard JavaScript reassignment feature to work the same in Vento.

Please let me know if you need more info or examples, I'd be happy to provide them.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions