Introduction

A powerful repeating data structure field type.

Heads Up: The Grid field type is a paid addon! Please checkout our store or ask about our developer partnership for repository access.

Configuration

Below is a list of available configuration with default values:

"example" => [
    "type"   => "anomaly.field_type.relationship",
    "config" => [
        "related"        => [],
        "max"            => null,
        "min"            => null,
    ]
]
Configuration
Key Example Description

related

[\Anomaly\GridsModule\Example\ExampleModel]

The related grid models. You can also define any models via API.

max

5

The maximum items allowed.

min

2

The minimum items allowed.

Usage

This section will show you how to use the field type via API and in the view layer.

Setting Values

Setting Grid values is best left to the control panel.

However, you can set the repeater field type value programmatically with a grid model instance:

$entry->example = $grid;

You can set the value with a collection of grid instances too:

$entry->example = $collection;

Lastly you can set the repeater field type value with an array of grid IDs:

$entry->example = [7, 8];

Basic Output

The grid field type always returns an \Anomaly\Streams\Platform\Model\EloquentCollection instance of related GridModel instances.

Example
$entry->example; // Collection of models.
Twig
{% for entry in entry.example %}

    {% if entry.type == 'books' %}
        <h2>{{ entry.title }}</h2>
        <p>{{ entry.description }}</p>
    {% endif %}

    {% if entry.type == 'movies' %}
        {{ entry.cover.thumbnail|raw }}
        <h2>{{ entry.title }}</h2>
        <p>{{ entry.description }}</p>
    {% endif %}

{% endfor %}

Including Partials

A more elegant way of rendering different grid types would use Twig's include feature. Assuming your page has a Grid field with the slug content assigned to it your page type's layout might look like this:

{% for section in page.content %}
    <div class="section {{ section.type }}-section-type">
        {% include "theme::sections/" ~ section.type %}
    </div>
{% endfor %}

Presenter Output

When accessing the field value from a decorated entry model the collection will contain instances of \Anomaly\GridFieldType\Grid\GridPresenter.

Example
$decorated->grid->first()->email->mailto('Email me!');
Twig
{{ decorated.grid.first().email.mailto('Email me!')|raw }}