Allow ‘empty’ value for more dynamic view-blocks

Created on 11 October 2024, about 1 month ago

Problem/Motivation

Hello Maintainers
Thank you for this module, first. I am using it in a largely terms based project.

It would be wonderful if the context field could allow an empty field (there is a similar but structurally different module which has the option ‘Allow empty field’).

Why? My use case

If you have, in my example, some content with two terms and some with three terms, you need
- two different view-block
- two different paths of the same type of content to distinguish where the first or second block view should be displayed.

My workaround

While looking for a possible solution, I came up with an idea:
- Use a ‘false term’ that is always inserted as the third term, let's call it ‘JohnDoe’.
- Do not show the third field in the node if the term is ‘JohnDoe’.

This is the code in the twig file that hides the field with the false term:

{% set termName = node.field_third_term.entity.getName() %} 
{% if termName and termName != 'JohnDoe' %}
  <div class="third-term">
    {% for item in node.field_secondary_term %}
      <a href="{{ path('entity.taxonomy_term.canonical', {'taxonomy_term': item.target_id}) }}">
      {{ node.field_third_term.entity.label }}</a>
    {% endfor %}
  </div>
{% endif %}

In this way, the one view-block I am using shows similar content whether the node has two or three real terms, setting only one view and avoiding having to set up complicated paths.

My wish

(which I think could extend the potential of this module and be useful in many situations)
This is my use case, but if the empty (or null, I am not sure which is more correct) value were allowed in the context fields, the view block could be much more dynamic in combining context entities

Grateful for your attention and reply

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇮🇹Italy senzaesclusiva

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024