eZ Platform Discussions

Retreive field content


I am trying to render the field ‘intro’.

All of the above works, but this code fails…

{% for item in items.searchHits %}

{{ ez_content_name(item.valueObject.contentInfo.intro) }}
{# { ez_field_value( item.content, 'intro' ) } #} {# { ez_field_value( item.valueObject.content, 'intro') } #} {#

{{ ez_render_field ( item.valueObject.content, 'intro') }}

#} {# { dump(item) } #} {% endfor %}

Regards, Atle

Yes, ez_econtent_name() won’t work on field level. Check how to use it in below doc link https://doc.ezplatform.com/en/latest/guide/twig_functions_reference/#ez_content_name
If you define on ContentType level the content name pattern as following:< title >. The content name which ez_econtent_name() will render is the title.

Hi da_real and thanks for engageing.

I’m sorry for being unclear. It is the statement:

{{ ez_render_field ( item.valueObject.content, ‘intro’) }}

I seek to get working, aka access the field (in this case rich text), but all my efforts end in an exception.

Regards, Atle

oh, I see the problem:
This is the right statement:
{{ ez_render_field ( item.valueObject, 'intro') }}

The valueObject contains already the content value eZ\Publish\Core\Repository\Values\Content\Content

btw take care about the quotes and both are wrong and throw variable not found exeption ;). Single quote ' is the right one, but may be the copy/paste here in Editor change the format

Hey da_real.

The above suggested statement produces the following error: Type error: Argument 2 passed to eZ\Publish\Core\MVC\Symfony\Templating\Twig\Extension\FieldRenderingExtension::eZ\Publish\Core\MVC\Symfony\Templating\Twig\Extension{closure}() must be an instance of eZ\Publish\API\Repository\Values\Content\Content, instance of eZ\Publish\Core\Repository\Values\Content\Location given, called in /home/ezp/dev/var/cache/dev/twig/2e/2eea377a70dcce1ad560bf71755dc16b332646e4fa9e10ff28029198474a869f.php on line 134

Regards, Atle

Hello !

This error means that your valueObject is a Location and not a content, so your first try

should be working (with the right quotes). Could you give us the exception you get in this case ?

Or just use Site API to make your life easier :slight_smile:
For example: https://github.com/netgen/ezplatform-site-api/blob/master/EXAMPLES.md#13-an-example-of-usage-from-twig

{% set children = location.filterChildren(['blog_post'], 10, 2) %}
<p>Parent name: {{ location.parent.content.name }}<p>
<p>Total blog posts: {{ children.nbResults }}</p>

{% for child in children %}
    <li>{{ child.content.name }}</li>
{% endfor %}

Hi amval.

With the right quotes it works as you say. Thanks for the help :smile:

Regards, Atle

Hi gof.

I tried your solution, but it did not work, it raised an exception stating amongst other things that filterChildren does noe exist.

But, as you can see the problem is solved :smile: It was as simple as quotes :blush:
Regards, Atle

Of course it didn’t work, you probably didn’t install first: https://github.com/netgen/ezplatform-site-api :slight_smile: