Introduction

anomaly.module.variables

The Variables module provides a powerful global variables management system.

Features

The Variables module comes with everything you need to manage groups of variables.

  • Streams Based
  • Multiple Groups
  • Included Plugin

Installation

You can install the Variables module with the addon:install command:

php artisan addon:install anomaly.module.variables
Notice: The Variables module comes installed with PyroCMS out of the box.

Usage

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

Variables

Variables are fields on a group entry that can be used to store information to use throughout your website or application.

Variable Repository

This class will go over the \Anomaly\VariablesModule\Variable\Contract\VariableRepositoryInterface

VariableRepositoryInterface::get()

The get method returns the raw data for the variable specified in a given group.

Returns: mixed
Arguments
Key Required Type Default Description

$group

true

string

none

The slug of the group you want to access.

$field

true

string

none

The slug of the variable field in the group you want to access.

Example
$variables->get('social', 'facebook_url'); // https://facebook.com/pyrocms
VariableRepositoryInterface::presenter()

The presenter method returns the field type presenter for the variable specified in a given group.

Returns: \Anomaly\Streams\Platform\Addon\FieldType\FieldTypePresenter or null
Arguments
Key Required Type Default Description

$group

true

string

none

The slug of the group you want to access.

$field

true

string

none

The slug of the variable field in the group you want to access.

Example
$variables->presenter('social', 'facebook_url')->link('Facebook'); // <a href="https://facebook.com/pyrocms">Facebook</a>
VariableRepositoryInterface::group()

The group method returns the entire group entry model so you can then easily access any variable on said model.

Returns: \Anomaly\Streams\Platform\Entry\Contract\EntryInterface or null
Arguments
Key Required Type Default Description

$group

true

string

none

The slug of the group you want to access.

Example
$group = $variables->group('social');

echo $group->facebook_url; // https://facebook.com/pyrocms
echo $group->twitter_url; // https://twitter.com/pyrocms

echo $group->getFieldTypePresenter('facebook_url')->link('Facebook'); // <a href="https://facebook.com/pyrocms">Facebook</a>

Plugin

This section will go over how to use the plugin that comes with the Variables module.

variable

The variable function returns the field type presenter for the variable specified in a given group.

Returns: \Anomaly\Streams\Platform\Addon\FieldType\FieldTypePresenter or null
Arguments
Key Required Type Default Description

$group

true

string

none

The slug of the group you want to access.

$field

true

string

none

The slug of the variable field in the group you want to access.

Twig
{{ variable('social', 'facebook_url').link('Facebook')|raw }} // <a href="http://facebook.com/pyrocms">Facebook</a>

variable_value

The variable_value function returns the raw data for the variable specified in a given group.

Returns: mixed
Arguments
Key Required Type Default Description

$group

true

string

none

The slug of the group you want to access.

$field

true

string

none

The slug of the variable field in the group you want to access.

Twig
{{ variable_value('social', 'facebook_url') }} // https://facebook.com/pyrocms

variable_group

The variable_group function returns the entire decorated group entry model so you can then easily access any variable on said model.

Returns: \Anomaly\Streams\Platform\Entry\EntryPresenter or null
Arguments
Key Required Type Default Description

$group

true

string

none

The slug of the group you want to access.

Twig
{{ variable_group('social').facebook_url }} // https://facebook.com/pyrocms (__toString output)
{{ variable_group('social').facebook_url.value }} // https://facebook.com/pyrocms (raw value)
{{ variable_group('social').facebook_url.link('Facebook') }} // <a href="https://facebook.com/pyrocms">Facebook</a>

// Or set as a Twig variable

{% set group = variable_group('social') %}

{{ group.facebook_url.link('Facebook') }} // <a href="https://facebook.com/pyrocms">Facebook</a>