handlebars-rust icon indicating copy to clipboard operation
handlebars-rust copied to clipboard

Issue referencing @key after #with

Open HectorCastelli opened this issue 1 year ago • 1 comments

Hello! First of all, thanks a lot for your hard work on this library!

Issue Description

I have found a case where the library behaves differently than handlebars.js:

Here is the setup:

Template

# {{data.name}}

{{#each data.related as |related|}}
{{#with (lookup ../other.contents @key) as | other_related |}}
## [{{other_related.name}}](/{{@key}})
{{related.relationship}}
{{/with}}
{{/each}}

Data

{
    "data": {
        "name": "John",
        "related": {
            "mary": {
                "relationship": "Siblings"
            }
        }
    },
    "other": {
        "contents": {
            "john": {
                "name": "John",
                "related": {
                    "mary": {
                        "relationship": "Siblings"
                    }
                }
            },
            "mary": {
                "name": "Mary"
            }
        }
    }
}

Expected output

# John

## [Mary](/mary)
Siblings

Actual output

# John

## [Mary](/)
Siblings

This is a link to the handlebars' playground showing what I am attempting to do: here.

This is a link to a repository that can be cloned to reproduce the issue: here.

Further notes

The main issue seems to be referencing @key inside a {{#with}} block.

Do you have any insights on why this is the case, if there is a setting I overlooked in the library, or if there are workarounds?

I am more than happy to help, albeit a little ~~bad~~ inexperienced with rust.

Thanks in advance!

HectorCastelli avatar Jul 04 '23 20:07 HectorCastelli

It seems there is an incompatible path resolution with with block. In handlebars-rust, you can use {{@../key}} to get mary. I will look into this issue and try to fix it on 5.0 release channel.

sunng87 avatar Jul 05 '23 14:07 sunng87