I customized the template :

commerce-product.html.twig

I want to display a link to the product like this but using twig:

<a href="/my-product-link" title="my-product-title"></a>

How to add the link to the product in twig ?

Comments

zenimagine created an issue. See original summary.

bojanz’s picture

There is a product_url variable documented in that template, can you try that?

zenimagine’s picture

Thank you, here is my current template (it's my first twig template).

commerce-product--produit--teaser-relation.html.twig

I have a problem :

- the {{ product.product_url }} code displays a link to the current page. The problem is that the products are in one block on another page.
How to display the product link (not the page)?

- the title {{ product.title }} also displays the tags, I only want the text. How to do this ?

<article{{ attributes }}>

    <div class="view-teaser-produit">
    <div class="views-row">

      <div class="views-teaser-type">
        Produit
      </div>

      <div class="views-teaser-image">
        {{ product.field_produit_image.0 }}
      </div>

      <h3 class="views-teaser-title">
        {{ product.title }}
      </h3>

      <div class="views-teaser-variation">
        {{ product.variation_price }}
        {{ product.variations }}
      </div>

      <div class="views-teaser-like-count">
        <span class="fa-layers fa-fw">
          <i class="fas fa-bookmark"></i>
          <span class="fa-layers fa-fw">
            <i class="fas fa-heart"></i>
            <span class="fa-layers-text">0</span>
          </span>
        </span>
      </div>

      <div class="views-teaser-like">
        {{ product.flag_like_product }}
      </div>

      <div class="views-teaser-relation-store">
        <div class="views-teaser-relation-store-image">
          {{ product.store_field_professionnel_logo }}
        </div> 
        <div class="views-teaser-relation-store-name">
          Ce produit est proposé par la boutique {{ product.store_title }}
        </div>
      </div>

      <div class="views-teaser-more-link">
        Voir la fiche produit
      </div>

      <div class="views-teaser-link">
        <a href="{{ product.product_url }}" title="{{ product.title }}"></a>
      </div>

    </div>
    </div>

</article>
saurabh.dhariwal’s picture

@zenimagine, I review your issue & I made change like:

<a href="{{product_url}}" title="my-product-title">{{ product.title }}</a>

Please try with this, Maybe it resolves your Query.

Thanks!.

bojanz’s picture

- the {{ product.product_url }} code displays a link to the current page. The problem is that the products are in one block on another page.
How to display the product link (not the page)?

That's a custom scenario, which means you will need custom code (your own preprocess function that adds a link to the current page that contains the block).

- the title {{ product.title }} also displays the tags, I only want the text. How to do this ?

That's a matter of formatter setup. Go to the "Manage display" screen for your product type and reconfigure the title formatter.

bojanz’s picture

Status: Active » Closed (outdated)