Find the Exponential Software extensions you want
UNIX name | Owner | Status |
---|---|---|
ezplatform-content-variables | 7x | stable |
Version | Compatible with |
---|---|
N/A | N/A |
This bundle provides a way to manage content variables. Basically, those are placeholders you can use anywhere in your content (in any field types). And they will be replaced with actual values during the page rendering.
Require contextualcode/ezplatform-content-variables via composer:
composer require contextualcode/ezplatform-content-variables
Activate the bundle in config/bundles.php:
ContextualCode\EzPlatformContentVariablesBundle\EzPlatformContentVariablesBundle::class => ['all' => true],
Add bundle routes in config/routes/ezplatform_content_variables.yaml:
content_variables:
resource: "@EzPlatformContentVariablesBundle/Resources/config/routing.yaml"
If you're using Kaliop eZ-Migration Bundle
php bin/console kaliop:migration:migrate
If you're using DoctrineMigrationsBundle
php bin/console doctrine:migrations:migrate --configuration=vendor/contextualcode/ezplatform-content-variables/src/bundle/Resources/config/doctrine_migrations.yaml
If you're not using any migration bundle, execute SQL manually
mysql < vendor/contextualcode/ezplatform-content-variables/src/bundle/MigrationVersions/20191009101530_mysql_create_cc_content_variable_table.sql
Clear the caches:
php bin/console cache:clear
Compile the assets:
yarn encore dev
Update JavaScript translations:
php bin/console bazinga:js-translation:dump web/assets --merge-domains
All the content variables are grouped in the collections. So first you would need to define those collections. To do so,
open an eZ Platform admin interface and go to "Content > Variables". And create a first content variables collection.
After the collection is created, you would need to add some variables. Click on the collection name and add
a few content variables. You would need to specify the following parameters for each variable:
There are two types of content variables: static and callback. No default callbacks are provided out of the box,
but it is very easy to create a new one:
Create a new AppBundle\ContentVariables\Random service (src/AppBundle/ContentVariables/Random.php),
which extends ContextualCode\EzPlatformContentVariables\Variable\Value\Callback.
namespace AppBundle\ContentVariables;
use ContextualCode\EzPlatformContentVariables\Variable\Value\Callback;
class Random extends Callback
{
protected $identifier = 'random';
public function getValue(): string
{
return random_int(0, 100);
}
}
Tag AppBundle\ContentVariables\Random with content_variables.value.callback:
AppBundle\ContentVariables\Random:
tags: [content_variables.value.callback]
Thats all, now when you add/edit any content variable you would be able to choose random callback for it.
After some content variables are created, you can use them in any content fields. To do so, please use a variable
identifier wrapped with # sign. For example, if you have a variable with random_var identifier,
try to add #random_var# to some pages content. And check edited content on the front-end siteaccess.
An actual random number should be shown instead of #random_var#.