Skip to content

Commit

Permalink
Merge pull request #174 from wonknu/group_tag_abe
Browse files Browse the repository at this point in the history
Group tag abe
  • Loading branch information
gregorybesson committed Mar 23, 2017
2 parents 4558627 + fd74374 commit 0bd95f9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
Binary file added docs/assets/abe-each.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/single-group.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions docs/types/abe-each.md
@@ -0,0 +1,52 @@
# Abe block each

> group elements
###Basic example

```html
{{#each myblock}}
​ <div>
{{abe type='text' key='myblock.text' desc='text item of the block'}}
</div>
​ <img src="{{abe type='image' key='myblock.image' desc='image item of the block'}}" />

<button>
{{abe type='text' key='button' desc='this button label is not part of this each statement'}}
</button>
{{/each}}
```

*Result :*

![Each](../assets/abe-each.png)

We have now a block each myblock that can be repeated as many time as we want with the '+' icon

Notice that since the <button> doesn't have ```key='myblock.button'``` but instead ```key='button'``` it won't be part of the each statement

When the input button will have some content, any item each from myblock will have the same text for the element button

Use case :

Each statement are usefull for exemple for Carousel, list of element with un unknow number of item etc ...


###Grouped element

Sometime we want to have a group of element but not inside of each statement because this group won't be repeated.

To do that, just use the same syntaxe as each block element but without wrapping them inside {{#each}} ... {{/each}} tag

```html
<div>
{{abe type='text' key='myblock.text' groupdesc='description for my group' desc='text item of the block'}}
</div>
​ <img src="{{abe type='image' key='myblock.image' groupdesc='description for my group' desc='image item of the block'}}" />
```

Notice groupdesc attribut that is use to write a description for our single grouped element

*Result :*

![SIngleEach](../assets/single-group.png)
2 changes: 1 addition & 1 deletion src/cli/cms/editor/handlebars/compileAbe.js
Expand Up @@ -52,7 +52,7 @@ export default function compileAbe(){
try {
value = eval('content.' + hash.key)
}catch(e) {
value = hash.key
value = ''
}
}else {
value = hash.key
Expand Down
4 changes: 3 additions & 1 deletion src/cli/cms/editor/handlebars/printBlock.js
Expand Up @@ -10,7 +10,9 @@ export default function printBlock (ctx, root) {

if(ctx[0].block != null && ctx[0].block !== '') {
res += `<div class="form-group" data-precontrib-templates="${ctx[0].precontribTemplate}">
<label class="title">${ctx[0].block}</label>
<label class="title">
${(ctx[0].groupdesc != null) ? ctx[0].groupdesc : ctx[0].block}
</label>
<div class='single-block well well-sm'>`
Array.prototype.forEach.call(ctx, (item) => {
if (precontrib) item.value = ''
Expand Down

0 comments on commit 0bd95f9

Please sign in to comment.