Partial

Partial

Form UI

The partial UI element renders a partial, the path value can refer to a partial view file otherwise the field name is used as the partial name.

content:
    label: Content
    type: partial
    path: field_content

The following field properties are supported.

Property Description
path path to a partial view file or view template code, defaults to the field name with field_ as a prefix.

When the path is set to an unqualified file name (a file name without a directory path and extension), the source path is determined to be in the model or controller directories. The following example will check for the partial file at ../models/mymodel/_field_for_content.php or ../controllers/mycontroller/_field_for_content.php.

content:
    type: partial
    path: field_for_content

You may specify a fully qualified path to access partials outside the model or controller directories. This can be useful for sharing partials between definitions.

content:
    type: partial
    path: $/acme/blog/partials/_field_content.php

# Accessing Variables

The following variables are available inside the partial when it is rendered.

  • $value is the current field value, if found.
  • $model is the model used for the field
  • $field is the configured class object Backend\Classes\FormField

Here is an some example contents of the _field_content.php file.

<?php if ($model->is_active): ?>
    <p><?= $field->label ?> is active</p>
<?php endif ?>

# Using View Templates

You may pass a view template code as the path to access view service templates inside the plugin. The following code would be found at the path plugins/acme/blog/views/formfields/content.php.

content:
    type: partial
    path: acme.blog::formfields.content

The path must contain the :: characters to activate the view service.

# See Also