...
Code Block |
---|
{% block eztweet_field %} {% spaceless %} {% set field_value %} {{ field.value.contents|raw }} {% endset %} {{ block( 'simple_block_field' ) }} {% endspaceless %} {% endblock %} |
fieldValue
is set to the markup we had above, using a {% set %}
block. We then call the block
function to process the simple_block_field
template block.
Registering the template
As explained in the FieldType template documentation, a FieldType template needs to be registered in the eZ Publish semantic configuration. The most basic way to do this would be to do so in ezpublish/config/ezpublish.yml
:
Code Block | ||
---|---|---|
| ||
ezpublish: global: field_templates: - { template: "EzSystemsTweetFieldTypeBundle:fields:eztweet.html.twig"} |
However, this is far from ideal. We want this to be part of our bundle, so that no manual configuration is required. For that to happen, we need make our bundle extend the eZ Publish semantic configuration. To do so, we are going to make our bundle's dependency injection extension (DependencyInjection/EzSystemsTweetFieldTypeExtension.php
) implement Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface
. This interface will let us prepend bundle configuration:
Code Block | ||||
---|---|---|---|---|
| ||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\Yaml\Yaml; class EzSystemsTweetFieldTypeExtension extends Extension implements PrependExtensionInterface { public function prepend( ContainerBuilder $container ) { $config = Yaml::parse( __DIR__ . '/../Resources/config/ezpublish_field_templates.yml' ); $container->prependExtensionConfig( 'ezpublish', $config ); } } |
The last thing to do is move the template mapping from ezpublish/config/ezpublish.yml
to Resources/config/ezpublish_field_templates.yml
:
Code Block |
---|
system: default: field_templates: - {template: "EzSystemsTweetFieldTypeBundle:fields:eztweet.html.twig"} |
Notice that the ezpublish
yaml block was deleted. This is because we already import our configuration under the ezpublish
namespace in the prepend method.
You should now be able to display a content item with this fieldtype from the frontoffice, with a fully functional embed: