Thanks to visit codestin.com
Credit goes to github.com

Skip to content

subexpression confusion/problem? #743

@waynedpj

Description

@waynedpj

ahoy all,

as you can see from this simple JSFiddle i am having a problem using the result of a helper in a sub expression as input to another helper. with the following helpers:

Handlebars.registerHelper("findRoot", (path, helperData) ->                       
                          newRoot = path.split("/")[0..1].join("/")
                          return new Handlebars.SafeString(newRoot))

Handlebars.registerHelper("rebase", (path, root, helperData) ->
                          return new Handlebars.SafeString(root + path))

template:

    {{#each pages}}
        findRoot = {{findRoot base}}</br>
        rebase = {{rebase ID.path (findRoot base) option=false}}</br>
    {{/each}}

and context:

context = 
    pages: [
            {base: "/Root/A", ID: {path: "/A/1"}},
            {base: "/Root/B", ID: {path: "/B/2"}}
            ]

the return value of the findRoot helper when used as a sub expression is being fed as an object to rebase instead of as a string. note that when findRoot is run normally (not as a sub expression) the return value is a string and everyone is happy.

i have tried with/without Handlebars.SafeString and no luck. i debugged it as far as the Handlebars compiler which builds the stack/depth stuff under the hood and did not see anything obviously amiss.

it seems like for some reason the entire ID object is getting passed in where i assume the string returned from findRoot should be?!

while i realize that i most likely i am not using Handlebars correctly, i have been digging at this for quite a bit and am beginning to think that maybe there is something going on here, like a bug?

thanks in advance for any help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions