Skip to content

Including Tailor content

Using components

Including Tailor content in Boxes is very easy. Just add either the collection or section component to your yaml config:

yaml
# tailor-example.yaml
name: Tailor example
handle: tailor-example

components:
    projects:
        component: collection
        properties:
            handle: "YourContent\\Projects"

Then you can access the Tailor content in your partial directly:

twig
{# tailor-example.htm #}

{% for project in projects %}
    ...
{% endfor %}

Using a record finder

If you want to provide a method to select the Tailor Entry that is related to your Box, a recordfinder component can be used. In this example, a blog_post is related to the Box:

yaml
# recordfinder-example.yaml
name: Record finder
handle: recordfinder-example
eagerLoad:
- blog_post # Don't forget to eager load the relation.
form:
    fields:
        blog_post: # Relation has to be added, see below!
            type: recordfinder
            nameFrom: title
            label: Blog Post

For this to work, you need to add the appropriate relation to your Box model in the app/Provider.php:

php
<?php
    // app/Provider.php
    public function boot()
    {
        parent::boot();

        \OFFLINE\Boxes\Models\Box::extend(function ($box) {
            // Add the "blog_post" relation to the Box model.
            // Make sure to use the correct Tailor Blueprint UUID.
            $box->belongsTo = [
                'blog_post' => [
                    \Tailor\Models\EntryRecord::class,
                    'blueprint' => 'your-tailor-blueprint-uuid',
                    'replicate' => false
                ]
            ];
            // Make sure the Tailor blueprints are properly loaded
            // for the new relation.
            $box->initializeBlueprintRelationModel();
        });
    }