- Issue created by @senzaesclusiva
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’).
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.
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.
(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
Active
1.0
Code