I have a block in a page that is a view with a contextual filter.
As a block does not have a path, I have to provide a default value "raw value from URL" as per Contextual filter with a block view
This all works as it should, the view in the block gets filtered per the URL's last/third component as configured in the contextual filter's settings.
I use this block both in an overview mode where it shows all the entities, grouped by a field (when the third path component is missing) and in a more detailed mode where I just want to show the entities without the grouping's title.
As the contextual filter already reduces the entity set to only one group, this group's title is redundant and ugly.
However, when using a "default value" the contextual filter's config does not let me override the title.
What I came up with - which seems like too much of a hack - is the following in views-view-grid--{view name}--block.html.twig
{% set parts = url("<current>")|render|render|split('/') %}
{% if parts[5] is empty %}
{# not a contextually filtered block, so show a title #}
{% if title %}
<h2>{{ title }}</h2>
{% endif %}
{% endif %}
I am just counting path components, which seems a little too vague to me.
Is there any better solution using just the view's (contextual filter) config? Any module to extend the view config options?
Or, alternatively, how can I determine if a view received a contextual filter in twig? I am generally having a hard time finding the available "objects" and their "methods"/parameters in twig as I could not find a good, complete reference. Why do I need to |render|render for example? What parameters does the url() function take? Can I count characters in a string with twig more easily than I did above? Pointers appreciated.