Rust-CMS / radical

A Rusty Wordpress Replacement.
MIT License
59 stars 7 forks source link

Allow for #each use with custom fields. #22

Closed SpBills closed 3 years ago

SpBills commented 3 years ago

Code example:

{{#each (getarray "colors") as |t| }}
    <div class="card d-flex flex-column p-5 m-2 w-25">
        <div class="card-body">
            <h5 class="card-title">Title: {{t.title}}</h5>
            <p class="card-text">Name: {{t.content}}</p>
            <small>{{@index}}</small>
        </div>
    </div>
    {{else}}
    <p>WRONG</p>
{{/each}}

The getarray helper accesses the array_fields field on the data of the template. array_fields is a hashmap. We access the correct array by the argument of the getarray helper.