Provide config for Home page segment not rendered as a link

Created on 4 October 2024, 3 months ago

As Home page segment not rendered as a link ( https://www.drupal.org/project/easy_breadcrumb/issues/3421745 🐛 Home page segment not rendered as a link Fixed )
changes went in https://www.drupal.org/project/easy_breadcrumb/releases/2.0.7 of this module. Links are not visible, even someone override the first link through twig then link is not coming only text is coming.

So I guess we should make this behavior to controlled through some config provided by this module

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇮🇳India nitesh624 Ranchi, India

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @nitesh624
  • 🇮🇳India nitesh624 Ranchi, India
  • 🇩🇪Germany spuky

    So just to check if I understood yo correctly...

    You want an Option to have a Home segment.. But it should not be Linked ?

    But you are describing links not showing ?

    Can you share the twig code you are using....

  • 🇮🇳India nitesh624 Ranchi, India

    Here is my overriden twig

    {% if breadcrumb %}
      <nav class="breadcrumb" role="navigation" aria-labelledby="system-breadcrumb">
        <h2 id="system-breadcrumb" class="visually-hidden">{{ 'Breadcrumb'|t }}</h2>
        <ol>
        {% for item in breadcrumb %}
          <li>
            {% if item.url %}
              {# Check the First Breadcrumb and custom #}
              {% if loop.first %}
                <a href="{{ custom_url }}">{{ item.text }}</a>
              {% else %}
                <a href="{{ item.url }}">{{ item.text }}</a>
              {% endif %}
            {% else %}
              {{ item.text }}
            {% endif %}
          </li>
        {% endfor %}
        </ol>
      </nav>
    {% endif %}
  • 🇩🇪Germany spuky

    looks fine on a first look you might try....

    {{ custom_url|raw }}

    drupal filters might clean your url from the output..

  • 🇺🇸United States Greg Boggs Portland Oregon

    A small note on |raw. Raw disables twig's output escaping so users might be able to post JavaScript in the URL if you pass content through Raw. So, you'll want to make sure that content is escaped before it gets to Twig.

  • 🇮🇳India nitesh624 Ranchi, India

    I tried {{ custom_url|raw }} but that is also not working. Seems it would be great of you can make the changes make in https://www.drupal.org/project/easy_breadcrumb/issues/3421745 🐛 Home page segment not rendered as a link Fixed to include as part of config. As some sites might need to rendered home page as link in first breadcrumb

  • 🇩🇪Germany spuky

    you should get those changes.. in the Dev version there was just nor release since they where mergeded

  • 🇩🇪Germany spuky

    Changes are in...

    and I still don't get your Problem... If you are On the Homepage.. and there is a breadcrumb.. what is the point of putting out a link to the page I am on... since you got a custom Url... that you want to link to...

    your twig would take into account the no link case for the first element..

    {% if breadcrumb %}
      <nav class="breadcrumb" role="navigation" aria-labelledby="system-breadcrumb">
        <h2 id="system-breadcrumb" class="visually-hidden">{{ 'Breadcrumb'|t }}</h2>
        <ol>
        {% for item in breadcrumb %}
          <li>
            {% if item.url %}
              {# Check the First Breadcrumb and custom #}
              {% if loop.first %}
                <a href="{{ custom_url }}">{{ item.text }}</a>
              {% else %}
                <a href="{{ item.url }}">{{ item.text }}</a>
              {% endif %}
            {% else %}
              {# Check the First Breadcrumb and custom #}
              {% if loop.first %}
                <a href="{{ custom_url }}">{{ item.text }}</a>
              {% else %}
                 {{ item.text }}
              {% endif %}
            {% endif %}
          </li>
        {% endfor %}
        </ol>
      </nav>
    {% endif %}
  • 🇮🇳India nitesh624 Ranchi, India

    @spuky thanks for snippet in #9. Thats worked for me. It will falls under no url case

  • 🇮🇳India nitesh624 Ranchi, India

    but is this a kind of workaround solution?

  • 🇮🇳India nitesh624 Ranchi, India

    and I still don't get your Problem... If you are On the Homepage.. and there is a breadcrumb.. what is the point of putting out a link to the page I am on... since you got a custom Url... that you want to link to...

    Yes for the first breadcrumb item I want to print a custom external url of another site.

  • 🇩🇪Germany spuky

    The normal use case for having the Breadcrumb also on the homepage...
    is in my opinion to have it there for consistency off your layout... A link to the page you are already visiting does not really make sense...
    (a usecase that is already not the default)

    you can have links to pages you are visiting... by using "Make the current page title segment a link"
    then also the Frontpage will follow that behavior... Since when you are on the Frontpage the Frontpage is the current page...
    (also a use case I would only understand in special circumstances..)

    Now you are already overriding the Front page url by twig with a custom_url for the first element so this is already a workaround...
    since you want a different first element in the breadcrumb.
    Then why should it be more of a workaround to do that for all cases it can match ? It's just your first workaround done correctly..

    I don't know enough about you usecase to have a diffrent URL than the Frontpage url... there to give advice.

  • 🇩🇪Germany spuky

    you could do the check for first loop element before to make twig look a little cleaner...

    {% if breadcrumb %}
      <nav class="breadcrumb" role="navigation" aria-labelledby="system-breadcrumb">
        <h2 id="system-breadcrumb" class="visually-hidden">{{ 'Breadcrumb'|t }}</h2>
        <ol>
        {% for item in breadcrumb %}
          <li>
          {% if loop.first %}
               <a href="{{ custom_url }}">{{ item.text }}</a>
          {% else %}
            {% if item.url %}
                <a href="{{ item.url }}">{{ item.text }}</a>
            {% else %}
                 {{ item.text }}
            {% endif %}
          {% endif %}
          </li>
        {% endfor %}
        </ol>
      </nav>
    {% endif %}
  • 🇮🇳India nitesh624 Ranchi, India

    But what was the exact scenario which https://www.drupal.org/project/easy_breadcrumb/issues/3421745 🐛 Home page segment not rendered as a link Fixed fixes?

  • 🇩🇪Germany spuky

    as described in the ticket:

    When building the breadcrumb on pages one level below the home page, the module checks to see if the segment should be rendered as a link. In doing so, it checks whether the current $links array is empty and the option to show the current page as a link is selected. This means that on the first level of sub-pages the home page link will have the URL even though it is not the current page.

    This described the behaviour before 2.0.7 which was fixed by the code of this issue...

Production build 0.71.5 2024