Tom Maton
Tom Maton

Reputation: 1594

Pass string parameter into assemble partial

I'm trying to pass a string parameter into a partial

This is my call to my partial.

{{> loginButton hide-on-mobile}}

This is my partial

<a href="/login" class="login {{this}}">Log in</a>

For some reason the value isn't being displayed. What am I doing wrong as it's driving me mad!!

Update

As suggested below by harco gijsbers, I needed to pass through an object not a string.

I did it in the following way using the parseJSON helper

{{#parseJSON '{"extraClass": "hide-on-mobile"}'}}
    {{> loginButton }}
{{/parseJSON}}

Upvotes: 2

Views: 1473

Answers (1)

harco gijsbers
harco gijsbers

Reputation: 461

My best guess is "hide-on-mobile" is not an object. You cannot pass strings directly to an partial. You will need an object. Maybe the example below will help.

With this object:

loginBtn = {
      label: "log in",
      href: "/login",
      extraCSS: "hide-on-mobile"
    }

And this partial:

<a href="{{href}}" class="login {{extraCSS}}">{{label}}</a>

The result will be

<a href="/login" class="login hide-on-mobile">Log in</a>

When the partial is called like:

 {{> loginButton loginBtn}}

Upvotes: 3

Related Questions