Context and Meta objects¶
Why Meta objects?¶
Meta objects provides extra layer between your internal documents/entities and this what is available for theme developer (Templator). Thanks to this feature you can make more changes in Your project code and data structures without breaking templates.
How to create Meta?¶
Every Meta object requires Context
, Value
and Configuration
.
- Context - it’s special service class used for collecting all meta’s and resolving meta objects inside other meta’s
- Value - object or array with data
- Configuration - array with configuration definitions for provided object.
Create Meta
manually:
1 2 3 4 5 6 | <?php
...
use SWP\Component\TemplatesSystem\Gimme\Meta\Meta;
return new Meta($context, $value, $configuration);
|
Create Meta
with MetaFactory
:
1 2 3 4 5 6 7 8 9 | <?php
...
use SWP\Component\TemplatesSystem\Gimme\Factory\MetaFactory;
use SWP\Component\TemplatesSystem\Gimme\Meta\Meta;
$metaFactory = new MetaFactory($context);
return $metaFactory->create($value, $configuration);
|
What is Context?¶
Context
is a special service class used for collecting all meta’s and resolving meta objects inside other meta’s.
It can collect all available configurations for meta’s, and convert provided objects into meta’s when there is configuration for it.
Note
When property of Meta
object can be itself a Meta
instance (there is configuration for it) Context will automatically process it.
Example yaml configuration file for object (context can read config from .yml
files).
1 2 3 4 5 6 7 8 9 10 11 | name: article
class: "SWP\\Component\\TemplatesSystem\\Tests\\Article"
description: Article Meta is representation of Article in Superdesk Web Publisher.
properties:
title:
description: "Article title, max 160 characters, can't have any html tags"
type: text
keywords:
description: "Article keywords"
type: text
to_string: title
|
Note
Configurations are used to manually expose properties from provided data, and create documentation for templators.
All objects passed to template should be Meta’s.