Details

    • Type: Story Story
    • Status: Backlog
    • Priority: High High
    • Resolution: Unresolved
    • Affects Version/s: 5.2-beta1, 1.5.1, 1.6.0
    • Fix Version/s: None
    • Labels:

      Description

      Hi,
      it is impossible to override the blocks called from parent block with the 'block function':

      to reproduce this:

      declare a global template override:

      ezpublish.yml

      ezpublish:
          system:
              my_site:
                  field_templates:
                      - { template: SiteBundle:Fields:content_fields.html.twig, priority: 10 }
      
      

      override one of those functions:

      SiteBundle:Fields:content_fields.html.twig

       
      {% extends "EzPublishCoreBundle::content_fields.html.twig" %}
       
      {% block simple_block_field %}
              NEVER CALLED
      {% endblock %}
       
      {% block simple_inline_field %}
            NEVER CALLED
      {% endblock %}
      

      PR is in progress but i need an insight from the engineering team.

      Thanks

        Activity

        Hide
        Bertrand Dunogier added a comment - - edited

        After looking into it for a bit, I've come to the conclusion that this has never been supported.

        FieldTemplates are meant to be used to override, well, field templates, e.g. Twig blocks formatted as $FieldTypeIdentifier_field. simple_inline_field and simple_block_field are not field templates.

        ez_render_field() will look for a field template in the configured ones, and *if it finds a field template override (<identifier>field block), use it to render the field. As a matter of fact, if a FieldTemplate contains both one or more field template blocks, overrides of simple_block_field and simple_inline_field _in the same template will be used.

        But a template that only contains simple_block_field and/or simple_inline_field won't be picked up by ez_render_field().

        I see that as a feature request, but not as a bug. And a useful one, gotta admit.

        One workaround would be to define a FieldTemplate that overrides all the definitions, and just calls parent(), with a slightly higher priority than the one from EzPublishCoreBundle.

        Show
        Bertrand Dunogier added a comment - - edited After looking into it for a bit, I've come to the conclusion that this has never been supported. FieldTemplates are meant to be used to override, well, field templates, e.g. Twig blocks formatted as $FieldTypeIdentifier_field . simple_inline_field  and simple_block_field are not field templates. ez_render_field() will look for a field template in the configured ones, and *if it finds a field template override (<identifier> field block), use it to render the field. As a matter of fact, if a FieldTemplate contains both one or more field template blocks, overrides of simple_block_field and simple_inline_field  _in the same template will be used. But a template that only contains simple_block_field and/or simple_inline_field won't be picked up by ez_render_field() . I see that as a feature request, but not as a bug. And a useful one, gotta admit. One workaround would be to define a FieldTemplate that overrides all the definitions, and just calls parent() , with a slightly higher priority than the one from EzPublishCoreBundle.
        Hide
        Karnichi Mohamed added a comment -

        3 years later... But thanks for your feedback.

        Show
        Karnichi Mohamed added a comment - 3 years later... But thanks for your feedback.
        Hide
        Bertrand Dunogier added a comment -

        Better than never is it not Karnichi Mohamed ?

        Show
        Bertrand Dunogier added a comment - Better than never is it not Karnichi Mohamed ?
        Hide
        Karnichi Mohamed added a comment -

        Sure, see you in 3 years... once it's implemented, hopefully

        Show
        Karnichi Mohamed added a comment - Sure, see you in 3 years... once it's implemented, hopefully
        Hide
        Laura Kishimoto added a comment - - edited

        Thanks Bertrand Dunogier, and to Karnichi Mohamed to initially raising this as I've encountered this problem this week. For anyone else needing to override this block, the we did the following:

        Workaround

        Define a new block in your custom content_fields.html.twig:

        {% block our_block_field %}
           … whatever …
        {% endblock %}
        

        And then use the block definitions that can be overridden to point to this new block instead of `simple_block_field`. For example:

        {% block eztext_field %}
        {% spaceless %}
            {% set field_value = field.value|nl2br %}
            {{ block( 'our_block_field' ) }}
        {% endspaceless %}
        {% endblock %}
        

        Show
        Laura Kishimoto added a comment - - edited Thanks Bertrand Dunogier , and to Karnichi Mohamed to initially raising this as I've encountered this problem this week. For anyone else needing to override this block, the we did the following: Workaround Define a new block in your custom content_fields.html.twig : {% block our_block_field %} … whatever … {% endblock %} And then use the block definitions that can be overridden to point to this new block instead of `simple_block_field`. For example: {% block eztext_field %} {% spaceless %} {% set field_value = field.value|nl2br %} {{ block( 'our_block_field' ) }} {% endspaceless %} {% endblock %}
        Hide
        Bertrand Dunogier added a comment - - edited

        It won't necessarily be this long, Karnichi Mohamed

        But it is unfortunately not that simple, as I tried to explain above. The override selection process isn't really meant for this particular usage. But it would be convenient as those are very common.

        Thank you for the workaround Laura Kishimoto. I'm not sure I understand where the block eztext_field is defined ? I'm probably missing a step here.

        Unless I've missed the point of what you do, you could try the following:

        app/Resources/views/ez/simple_fields.html.twig

        {% extends "@EzPublishCore/content_fields.html.twig" %}
         
        {% block simple_inline_field %}
            {# block customization here #}
            {{ parent() }}
        {% endblock %}
        

        app/Resources/views/ezstring_field.html.twig

        {# Note how this extends the simple_fields template, not the one from core #}
        {% extends "ez/simple_fields.html.twig" %}
         
        {% block ezstring_field %}
            <pre>local eztext_field override</pre>
            {{ parent() }}
        {% endblock %}
        

        It won't change what the simple_inline_field block used by @EzPublishCore/content_fields.html.twig, but at least, every custom twig template can re-use the same simple_inline_field block.

        Show
        Bertrand Dunogier added a comment - - edited It won't necessarily be this long, Karnichi Mohamed But it is unfortunately not that simple, as I tried to explain above. The override selection process isn't really meant for this particular usage. But it would be convenient as those are very common. Thank you for the workaround Laura Kishimoto . I'm not sure I understand where the block eztext_field is defined ? I'm probably missing a step here. Unless I've missed the point of what you do, you could try the following: app/Resources/views/ez/simple_fields.html.twig {% extends "@EzPublishCore/content_fields.html.twig" %}   {% block simple_inline_field %} {# block customization here #} {{ parent() }} {% endblock %} app/Resources/views/ezstring_field.html.twig {# Note how this extends the simple_fields template, not the one from core #} {% extends "ez/simple_fields.html.twig" %}   {% block ezstring_field %} <pre>local eztext_field override</pre> {{ parent() }} {% endblock %} It won't change what the simple_inline_field block used by @EzPublishCore/content_fields.html.twig , but at least, every custom twig template can re-use the same simple_inline_field block.
        Hide
        Laura Kishimoto added a comment -

        Bertrand Dunogier: It's a core block definition from the vendor version of content_fields.html.twig, found here. It's one example of a block that points to the unchangeable simple_block_field - there are a few in that file.

        Show
        Laura Kishimoto added a comment - Bertrand Dunogier : It's a core block definition from the vendor version of content_fields.html.twig , found here . It's one example of a block that points to the unchangeable simple_block_field - there are a few in that file.

          People

          • Assignee:
            Unassigned
            Reporter:
            Karnichi Mohamed
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: