0

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?

doppelgreener
  • 4,809
  • 10
  • 46
  • 63

1 Answers1

1

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>
LukeAskew
  • 93
  • 2
  • 7
  • Thanks for checking this out, Luke. I caused a miscommunication here through some poor choice of words -- it's not that I want to have default values with the attributes I specify, but I want to use an attribute-less property: instead of `{{>button text='Some text'}}`, I want to use `{{>button 'Some text'}}` or `{{#button}}Some text{{/button}}`. Handlebars supports that, and Fab Assemble is built on Handlebars so I presume there's a way, but I'm not sure what the reference is for that attribute-less value: `{{content}}`, `{{body}}` etc don't work. – doppelgreener Apr 28 '17 at 11:01
  • That said this is kind of awesome and I didn't think about having this kind of behaviour, and it would be really useful inside the component library. [edits into project] – doppelgreener Apr 28 '17 at 11:16