Inner handlebars don't escape in href?

After searching don’t see an easy way to do this -

{{> navItem label="Log" href="{{concat '/get-log/' experience.user.userTags.cust}}" }}

Means the output is (handlebar char results in %7B) -'/get-log/'%20experience.user.userTags.cust%7D%7D

Have tried to escape like putting a \ before the {{}}, also tried the {{#with concat ‘one’ ‘two’ as url}} & {{/with}}, but no avail (experience page syntax requires " as the outermost chars in href, and syntax also doesn’t seem to recognize the #with helper);

So down to the href wants “” but nothing working within, guessing since that line is within the {{> navItem }} partial … but must be an easy way to make this eval, no?

You can pass values as arguments using this syntax:

{{> navItem label="Log" href=(concat '/get-log/' experience.user.userTags.cust) }}

However, concat is neither a built-in Handlebars helper nor a custom helper provided by Losant, so this is not going to work.

You could instead alter the inline helper definition to iterate over the href value, which would work whether you provide a string or an array as an argument. For example …

{{#*inline "navItem"}}
  <li class="nav-item">
    <a class="nav-link" href="{{#each href}}{{this}}{{/each}}">{{label}}</a>

{{> navItem label="Log" href=(array '/get-log/' experience.user.userTags.cust) }}
{{> navItem label="Log" href=pageData.myString}}
{{> navItem label="Log" href="/hello" }}

Thank you for the quick reply!
That larger context always helps too.

Hm, so the href in here still wants “” wrapper no?
Such that it’s not accepting the (array …) input.

No, because then you would be passing the literal string value (array '/get-log/' experience.user.userTags.cust) as the href argument. Instead, you want to pass the array you are constructing using the array helper. And then you are handling that array argument in the partial definition:

<a href="{{#each href}}{{this}}{{/each}}">

This approach is, in other words, The Poor Man’s {{concat}} Helper. :slight_smile:

You bet, I just mean the href doesn’t seem to like missing the “”…
but lemme check again if I missed a char somewhere

Ah got it, you’re awesome, cheers.

Ok now similarly,
For dynamic layouts in an Experience, for different tenants how best to do (array …) in the file helper?

{{file '/images/logo.png'}}


src={{ file (array '/images/' '{{pageData.cust}}' '/logo.png') }}

Coz it’s getting filename, but that filename depends on a User / Device.
EDIT - And back to ‘src’ wants a link, not helper

Try …

src="{{ file (array '/images/' pageData.cust '/logo.png') }}"

Ah shoot, the array puts a comma in the output (like separating elements in the array)…

And I don’t think concat is available …

Oh you’re right; Try this …

{{file (template '/images/{{cust}}/logo.png' pageData)}}

This makes use of the {{template}} helper. You could probably use this method for your original question as well.

By the way, we also have a template tester in our documentation where you can try these out and adjust your templates as required to get your desired output.

Really appreciate it!