Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Решено] Не активная последняя хлебная крошка twig


Recommended Posts

Подскажите, может кто делал, как на twig записать условие чтобы последняя хлебная крошка была не ссылкой просто текстом, чтобы не было ссылки на саму себя?

Просто на PHP? решение с форума

	<?php foreach ($breadcrumbs as $i=> $breadcrumb) { ?>
	<?php echo $breadcrumb['separator']; ?><?php if($i+1<count($breadcrumbs)) { ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a> <?php } else { ?><?php echo $breadcrumb['text']; ?><?php } ?>
	<?php } ?>

 

Edited by bogdan281989
уточнение
Link to comment
Share on other sites

Попробуйте так
 

{% for key, breadcrumb in breadcrumbs %}
    {% if key + 1 < breadcrumbs|length %}
        <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
    {% else %}
        <li>{{ breadcrumb.text }}</li>
    {% endif %}
{% endfor %}

 

  • +1 1
Link to comment
Share on other sites


2 минуты назад, thentru сказал:

Попробуйте так
 

{% for key, breadcrumb in breadcrumbs %}
    {% if key + 1 < breadcrumbs|length %}
        <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
    {% else %}
        <li>{{ breadcrumb.text }}</li>
    {% endif %}
{% endfor %}

 

Спасибо! На 100% верно отрабатывает. Думаю это будет полезно для всех кто работает с Opencart 3

Link to comment
Share on other sites

  • 5 months later...

Вот вам с микроразметкой Schema.org рабочий вариант

 

<ul class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList">
    {% for key, breadcrumb in breadcrumbs %}
	{% if key + 1 < breadcrumbs|length %}
      <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
	  <a itemscope itemtype="https://schema.org/Thing" itemprop="item" href="{{ breadcrumb.href }}"><span itemprop="name">{{ breadcrumb.text }}</span></a>
	  <meta itemprop="position" content="{{key+1}}" />
	  </li>
	   {% else %}
        <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><span itemprop="name">{{ breadcrumb.text }}</span>
		<meta itemprop="position" content="{{key+1}}" />
		</li>
    {% endif %}
    {% endfor %}
  </ul>

 

  • +1 1
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.