Skip to content
This repository was archived by the owner on Jan 1, 2020. It is now read-only.

Latest commit

 

History

History
34 lines (26 loc) · 1.55 KB

twig.md

File metadata and controls

34 lines (26 loc) · 1.55 KB

CreatePHP Documentation

Twig Extension

This library contains an extension to render objects in the twig templating language. Add the Midgard\CreatePHP\Extension\Twig\CreatephpExtension to your twig environment to get the following constructs:

{% createphp mymodel %}{{ mymodel_rdf|raw }}{% endcreatephp %}

The createphp tag loads your domain model object into the EntityInterface instance with the help of the RdfTypeFactory. You can specify the name for the rdf entity inside the createphp tag with the "as" attribute: {% createphp mymodel as="yourname" %}. If you do not specify a name, the name is generated by appending "_rdf" to your model name.

Inside the createphp tag, you can render the entity with the default structure (see above), or render single fields as in the example below:

{% createphp mymodel noautotag %}
<div class="my-section" {{ createphp_attributes(mymodel_rdf) }}>
    <h1 class="my-title" {{ createphp_attributes( mymodel_rdf.title ) }}>{{ createphp_content( mymodel_rdf.title ) }}</h1>
    {{ mymodel_rdf.content|raw }}
</div>
{% endcreatephp %}

With noautotag the enclosing elements are not rendered automatically. Therefore, you need to render the attributes of the entity in a tag that encloses all of your entity. Inside that tag, you can place arbitrary HTML and render single fields or render attributes and content of the fields separately for closer control over the generated HTML. Note the |raw filter after rendering the full entity or a complete field.