0

I've created a view to display products based on the taxonomy vocabulary Categories. I followed a few how tos and check for answers on drupal.org, here & other websites but none is working.

I would like the title of the view to be the name of taxonomy term displayed.

The Path is : taxonomy/term/% Contextual filter: -- When the filter value is NOT in the URL > Provide default value > Taxonomy Term ID from URL -- When the filter value IS in the URL or a default is provided > Specify validation criteria > Taxonomy Term ID -- -- Vocabulary > Categories

To overwrite the title, I have 2 Replacement patterns available :

{{ arguments.field_categories_target_id }} == Product: Catégories (field_categories) title
{{ raw_arguments.field_categories_target_id }} == Product: Catégories (field_categories) input

The both display the Taxonomy term ID, not the name.

I've tried with other replacement patterns, nothing is displayed.

I'm running Drupal 8.9.13.

Thanks for your help!

enter image description here


This is the .yml file.

uuid: cb266220-13c8-434d-8371-cabb6d7af36f
langcode: fr
status: true
dependencies:
  config:
    - commerce_product.commerce_product_type.dropixx
    - core.entity_view_mode.commerce_product.vignette
    - field.storage.commerce_product.field_categories
    - taxonomy.vocabulary.categories
    - taxonomy.vocabulary.marques_cat
  module:
    - commerce
    - commerce_product
    - ds
    - taxonomy
id: taxonomy
label: Taxonomy
module: views
description: ''
tag: ''
base_table: commerce_product_field_data
base_field: product_id
display:
  default:
    display_plugin: default
    id: default
    display_title: Master
    position: 0
    display_options:
      access:
        type: none
        options: {  }
      cache:
        type: tag
        options: {  }
      query:
        type: views_query
        options:
          disable_sql_rewrite: false
          distinct: false
          replica: false
          query_comment: ''
          query_tags: {  }
      exposed_form:
        type: basic
        options:
          submit_button: Apply
          reset_button: false
          reset_button_label: Reset
          exposed_sorts_label: 'Sort by'
          expose_sort_order: true
          sort_asc_label: Asc
          sort_desc_label: Desc
      pager:
        type: full
        options:
          items_per_page: 12
          offset: 0
          id: 0
          total_pages: null
          tags:
            previous: ‹‹
            next: ››
            first: ««
            last: »»
          expose:
            items_per_page: false
            items_per_page_label: 'Items per page'
            items_per_page_options: '5, 10, 25, 50'
            items_per_page_options_all: false
            items_per_page_options_all_label: '- All -'
            offset: false
            offset_label: Offset
          quantity: 5
      style:
        type: default
        options:
          row_class: 'col-xs-12 col-sm-6 col-md-6 col-lg-4 col-xl-3 vg-box'
          default_row_class: true
          uses_fields: false
      row:
        type: 'ds_entity:commerce_product'
        options:
          relationship: none
          view_mode: vignette
          alternating_fieldset:
            alternating: false
            allpages: false
            item_0: default
            item_1: default
            item_2: default
            item_3: default
            item_4: default
            item_5: default
            item_6: default
            item_7: default
            item_8: default
            item_9: default
          grouping_fieldset:
            group: false
          advanced_fieldset:
            advanced: false
      fields:
        title:
          table: commerce_product_field_data
          field: title
          id: title
          entity_type: null
          entity_field: title
          plugin_id: field
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: true
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: value
          type: string
          settings: {  }
          group_column: value
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
        field_categories:
          id: field_categories
          table: commerce_product__field_categories
          field: field_categories
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: true
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: target_id
          type: entity_reference_label
          settings:
            link: true
          group_column: target_id
          group_columns: {  }
          group_rows: true
          delta_limit: 1
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
          plugin_id: field
        nothing:
          id: nothing
          table: views
          field: nothing
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: true
            text: "<br>title {{ title }}\r\n<br>categories {{ field_categories }}\r\n<br>target id {{ arguments.field_categories_target_id }} "
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: false
          plugin_id: custom
      filters:
        status:
          value: '1'
          table: commerce_product_field_data
          field: status
          plugin_id: boolean
          entity_type: commerce_product
          entity_field: status
          id: status
          expose:
            operator: ''
            operator_limit_selection: false
            operator_list: {  }
          group: 1
        type:
          id: type
          table: commerce_product_field_data
          field: type
          value:
            dropixx: dropixx
          entity_type: commerce_product
          entity_field: type
          plugin_id: commerce_entity_bundle
          expose:
            operator_limit_selection: false
            operator_list: {  }
        field_stock_qty_value:
          id: field_stock_qty_value
          table: commerce_product__field_stock_qty
          field: field_stock_qty_value
          relationship: none
          group_type: group
          admin_label: ''
          operator: '!='
          value:
            min: ''
            max: ''
            value: '0'
          group: 1
          exposed: false
          expose:
            operator_id: ''
            label: ''
            description: ''
            use_operator: false
            operator: ''
            operator_limit_selection: false
            operator_list: {  }
            identifier: ''
            required: false
            remember: false
            multiple: false
            remember_roles:
              authenticated: authenticated
            placeholder: ''
            min_placeholder: ''
            max_placeholder: ''
          is_grouped: false
          group_info:
            label: ''
            description: ''
            identifier: ''
            optional: true
            widget: select
            multiple: false
            remember: false
            default_group: All
            default_group_multiple: {  }
            group_items: {  }
          plugin_id: numeric
        field_marque_target_id:
          id: field_marque_target_id
          table: commerce_product__field_marque
          field: field_marque_target_id
          relationship: none
          group_type: group
          admin_label: ''
          operator: or
          value: {  }
          group: 1
          exposed: true
          expose:
            operator_id: field_marque_target_id_op
            label: 'Marques :'
            description: ''
            use_operator: false
            operator: field_marque_target_id_op
            operator_limit_selection: false
            operator_list: {  }
            identifier: field_marque_target_id
            required: false
            remember: false
            multiple: false
            remember_roles:
              authenticated: authenticated
              anonymous: '0'
              administrator: '0'
            reduce: false
          is_grouped: false
          group_info:
            label: ''
            description: ''
            identifier: ''
            optional: true
            widget: select
            multiple: false
            remember: false
            default_group: All
            default_group_multiple: {  }
            group_items: {  }
          reduce_duplicates: false
          type: select
          limit: true
          vid: marques_cat
          hierarchy: false
          error_message: true
          plugin_id: taxonomy_index_tid
      sorts: {  }
      title: '<none>'
      header: {  }
      footer: {  }
      empty: {  }
      relationships: {  }
      arguments:
        field_categories_target_id:
          id: field_categories_target_id
          table: commerce_product__field_categories
          field: field_categories_target_id
          relationship: none
          group_type: group
          admin_label: ''
          default_action: default
          exception:
            value: all
            title_enable: false
            title: '{{ arguments.field_marque_target_id }}'
          title_enable: true
          title: '{{ arguments.field_categories_target_title }}'
          default_argument_type: taxonomy_tid
          default_argument_options:
            term_page: '1'
            anyall: ','
            node: false
            limit: false
            vids: {  }
          default_argument_skip_url: false
          summary_options:
            base_path: ''
            count: true
            items_per_page: 25
            override: false
          summary:
            sort_order: asc
            number_of_records: 0
            format: default_summary
          specify_validation: true
          validate:
            type: 'entity:taxonomy_term'
            fail: 'not found'
          validate_options:
            bundles:
              categories: categories
            access: true
            operation: view
            multiple: 0
          break_phrase: false
          not: false
          plugin_id: numeric
      display_extenders: {  }
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url
        - url.query_args
        - user
      tags:
        - 'config:field.storage.commerce_product.field_categories'
  taxonomy_category_contextual:
    display_plugin: page
    id: taxonomy_category_contextual
    display_title: Page
    position: 1
    display_options:
      display_extenders:
        metatag_display_extender: {  }
      path: taxonomy/term/%
      enabled: true
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url
        - url.query_args
        - user
      tags:
        - 'config:field.storage.commerce_product.field_categories'
3
  • See my D7 answer here. Same procedure except in D8/D9 you use {{ name }}.
    – No Sssweat
    Commented Jan 26, 2021 at 14:06
  • ThX, but it partially works. Taxonomy Term : name is not available. I'm displaying product fileds. With {{ field_categories }} in the title field, It displays all categories. If I select in Multiple field settings Display 1. It display the first Category title in all categories of the tree.
    – mChamps
    Commented Jan 26, 2021 at 15:27
  • In that case, you'll have to solve it programmatically. I show in this answer how to programmatically alter the view title.
    – No Sssweat
    Commented Jan 27, 2021 at 6:49

1 Answer 1

0

Hey there is there any particular reason you are using that filter?

I believe that if you use the "Has Taxonomy Term ID" contextual filter Like so, it will work as you intend it to.

Let me know if i did not understand your question correctly. Best Regards.

5
  • You understaood right. I am using the Overwrite Title field. It doesn't work. Nothing is displayed when I add {{ arguments.tid }}. Thanks for your suggestion.
    – mChamps
    Commented Jan 26, 2021 at 11:22
  • That pattern is not one that Views gave you?
    – Kevin
    Commented Jan 26, 2021 at 12:26
  • @mChamps I am suggesting also that you should use a different contextual filter, not just the different token. Have you tried that? Commented Jan 26, 2021 at 12:36
  • I've created the view from scratch. I am building a shop with Drupal Commerce and I want to be able to navigate with a category hierarchy, so I use Taxonomy. When I click on overwrite title, view gives me 2 replacement patterns. They display the taxonomy ID instead of the Taxonomy Name. How can I use a different contextual filter? It is the only available filter related to Taxonomy.
    – mChamps
    Commented Jan 26, 2021 at 13:59
  • You delete the one you have and use the one I suggester. I am sorry if I don't understand what the issue is. Would you mind sharing the whole yml file so that I can get some better insight on your problem and maybe help more actively? Commented Jan 27, 2021 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.