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.