doppelgreener
doppelgreener

Reputation: 5104

How can I include content of a component in Fabricator Assemble *without* a corresponding attribute, or at block level?

In Fabricator Assemble, I could have a component button.html:

<a class="button">{{text}}</a>

I can use this with the syntax {{>button text='Home'}}. Notably, I have to specify a name for the "text" attribute.

I'm looking to see how I can handle not needing to do that in Assemble. The Literals section of the docs for Handlebars (whiich Fabricator Assemble is built on) highlights an alternative syntax with which I could include a button:

{{>button 'Home'}}

In this example, "Home" is a value without any name for it at all. Handlebars also indicates the following is possible as a basic block:

{{#button}}
  <b>Some button content</b>
{{/button}}

Likewise, that content has no name.

I'd like to be able to do this same thing in Fabricator Assemble, but it doesn't seem to have a way for me to include this nameless content. In templates there's {% body %} but that doesn't work here.

In Handlebars, which Fabricator Assemble is based on, all examples for how to recreate this involve JavaScript, which doesn't translate well to Assemble.

What can I do to use {{>button 'Some text'}} or {{#button}}...{{/button}} syntax in Fabricator Assemble? Is this behaviour even available?

Upvotes: 0

Views: 64

Answers (1)

LukeAskew
LukeAskew

Reputation: 83

In the current version, the easiest way to achieve this is with a custom helper.

Add the following to the helpers option in your gulpfile.js:

default: (value, defaultValue) => {
  return value || defaultValue;
},

Then inside a handlebars template:

<div>
  {{default varName 'default value'}}
</div>

Upvotes: 1

Related Questions