-1

I created a view with the machine name cgv_product.

This view contains the fields "Product Name" and "Custom Text".

In the "Custom Text" field, the {{ name }} Twig code is available to display the product number.

I created a template with the name views-view-fields--cgv_produit.html.twig it works but if I put the Twig code {{ name }} in it it's not rendered.

How to display the product name in my template via Twig?

views-view-fields--cgv_product.html.twig

I tested the following codes in Twig and it does not work :

    <div class="flex-grow-1 bd-highlight"><i class="fas fa-signature fa-lg"></i>
      {{ fields.name.content }}
      {{ fields.field_name.content }}
      {{ row.content.name }}
      {{ name }}
    </div>

enter image description here

0

In the "Custom Text" field, {{ name }} is only available to render the "Product Name" field inside the "Custom Text" field (in the view UI), not in a twig template.

You should try to access your fields in the twig template like this {{ row.content.name }} (check the available fields using devel/kint).

  • I updated the question. I do not know how to use devel/kint – marsouin Apr 17 at 18:58
  • @marsouin – Download Devel, enabel Devel's sub-module Kint and then {{ kint() }}. – leymannx Apr 17 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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