0

When I use {{ path('entity.node.canonical', {'node': node.id}) }} in a node template file, it renders the path alias.

How can I get the canonical path?

2 Answers 2

3

{{ path('entity.node.canonical', {'node': node.id}, {'path_processing': false}) }}

-2

{# /**

  • @file
  • Theme override to display a view of unformatted rows.
  • Available variables:
    • title: The title of this group of rows. May be empty.
    • rows: A list of the view's row items.
    • attributes: The row's HTML attributes.
    • content: The row's content.
    • view: The view object.
    • default_row_class: A flag indicating whether default classes should be
  • used on rows.
  • @see template_preprocess_views_view_unformatted() */ #} {% if title %}

{{ title }}

{% endif %}

{% for row in rows %} {% set row_classes = [ default_row_class ? 'views-row', ] %} {% endfor %}

<div{{ row.attributes.addClass(row_classes) }}>

                <div> SHOOP</div>

{# The content type is named :"shop" If we have just added one node for in contente type "SHOOP", we can keep the node content type id with : {{ view.result.0.nid) }}. Il we have more node content type, we have to use the loop "for". And in order to reach each field value we use this followig method. Note thate, the active template was : "views-wiew--unuformated.htlm.twig". The suggested view that we create in the theme suggestion we be : "views-view--shop.html.twig"

#}

{% set items = view.result %} 

{#for each item 'of content type' #} 
{% for item in items %}
        
        {# Champ 'Title' of content type "SHOP"  #}
        {{ item._entity.title.value|raw}}

        {# Champ 'Image 1' du TDC "SHOP"  #}
         <img src="{{ file_url(item._entity.field_image_1.entity.uri.value) }}"/>

         {# Champ 'Image 2' of content type "SHOP"  #}
        <img src="{{ file_url(item._entity.field_image_2.entity.uri.value) }}"/>

        <img src="{{ file_url(item._entity.field_image_3.entity.uri.value) }}"/>

        {# field 'Description' of content type "SHOP"  #}
        {{ item._entity.field_description.value|raw }}

        {# Champ 'weight' of content type "SHOP" #}
        {{ item._entity.field_weight.value }}

<button type="button" class="btn btn-primary">
     <a href="{{ path('entity.node.canonical', {'node' : item.nid }) }}"> {{"See more"|t}}
    </a>  
</button> 
{% endfor %} 

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.