Loading Meta from template¶
Meta Loaders¶
Meta Loader
provides easy way for fetching data directly from template file.
Loader can return single meta or collection of meta’s (with MetaCollection
class).
Library provides ChainLoader
class witch can simplify work with many loaders.
Meta Loader
must implement Loader Interface.
How to load single Meta?¶
gimme¶
The tag gimme
has one required parameter and one optional parameter:
- (required) Meta object type (and name of variable available inside block), for example: article
- (optional) Keword
with
and parameters for Meta Loader, for example:{ param: "value" }
1 2 3 4 | {% gimme article %}
{# article Meta will be available under "article" variable inside block #}
{{ article.title }}
{% endgimme %}
|
Meta Loaders sometimes require special parameters - like the article number, language of the article, user id, etc..
1 2 3 4 | {% gimme article with { articleNumber: 1 } %}
{# Meta Loader will use provided parameters to load article Meta #}
{{ article.title }}
{% endgimme %}
|
How to load Meta collection?¶
gimmelist¶
The gimmelist
tag has two required parameters and two optional parameters:
- (required) Name of variable available inside block:
article
- (required) Keyword
from
and type of requested Metas in collection:from articles
with filters passed to Meta Loader as extra parameters (start
,limit
,order
)- (optional) Keyword
with
and parameters for Meta Loader, for example:with {foo: 'bar', param1: 'value1'}
- (optional) Keyword
without
and parameters for Meta Loader, for example:without {source: 'AAP'}
- (optional) Keyword
if
and expression used for results filtering- (optional) Keyword
ignoreContext
and optional array of selected meta to be ignored
Example of the required parameters:
1 2 3 | {% gimmelist article from articles %}
{{ article.title }}
{% endgimmelist %}
|
Example with ignoring selected context parameters:
1 2 | {% gimmelist article from articles ignoreContext ['route', 'article'] %}
...
|
Example with ignoring whole context
1 2 | {% gimmelist article from articles ignoreContext [] %}
...
|
Or even without empty array
1 2 | {% gimmelist article from articles ignoreContext %}
...
|
Example with filtering articles by metadata:
1 2 3 | {% gimmelist article from articles with {metadata: {byline: "Karen Ruhiger", located: "Sydney"}} %}
{{ article.title }}
{% endgimmelist %}
|
The above example will list all articles by metadata which contain byline
equals to Karen Ruhiger
AND located
equals to Sydney
.
To list articles by authors you can also do:
1 2 3 4 | {% gimmelist article from articles with {author: ["Karen Ruhiger", "Doe"]} %}
{{ article.title }}
Author(s): {% for author in article.authors %}<img src="{{ url(author.avatar) }}" />{{ author.name }} ({{ author.role }}) {{ author.biography }} - {{ author.jobTitle.name }},{% endfor %}
{% endgimmelist %}
|
It will then list all articles written by Karen Ruhiger
AND Doe
.
To list articles from the Forbes
source but without an AAP
source you can also do:
1 2 3 | {% gimmelist article from articles with {source: ["Forbes"]} without {source: ["AAP"]} %}
{% for source in article.sources %} {{ source.name }} {% endfor %}
{% endgimmelist %}
|
It will then list all articles with source Forbes
and without AAP
.
Listing article’s custom fields:
1 2 3 4 | {% gimmelist article from articles %}
{{ article.title }}
{{ article.extra['my-custom-field'] }}
{% endgimmelist %}
|
Example with usage of all parameters:
1 2 3 4 5 6 7 | {% gimmelist article from articles|start(0)|limit(10)|order('id', 'desc')
with {foo: 'bar', param1: 'value1'}
contextIgnore ['route', 'article']
if article.title == "New Article 1"
%}
{{ article.title }}
{% endgimmelist %}
|