verbb/hyper

Rendering a link from the same hyper link field with text override makes the text property displays twice on the second link

Closed this issue · 4 comments

Describe the bug

I've got a hyper link field that i use in my header navigation once; and the second time the same hyper link field on my mobile navigation. The same problem occurs of if paste the same code after each other.

I am overriding the text as described in the docs.

{% set linkContent %}
    <svg ... />
    Check out this link
{% endset %}

{{ entry.myLinkField.getLink({
    text: linkContent,
}) }}

My example code that bugs:

  {% if not globalNavigation.fieldLink.isEmpty() %}
      {% set linkContent %}
          <div class="relative z-20 h-full rounded-full border border-inherit bg-inherit px-6 py-3">
              {{ globalNavigation.fieldLink.text }}
          </div>test
      {% endset %}

      {{
          globalNavigation.fieldLink.getLink({
              text: linkContent,
              class: 'btn btn-primary group'
          })
      }}
  {% endif %}

  {% if not globalNavigation.fieldLink.isEmpty() %}
      {% set linkContent %}
          <div class="relative z-20 h-full rounded-full border border-inherit bg-inherit px-6 py-3">
              {{ globalNavigation.fieldLink.text }}
          </div>test
      {% endset %}

      {{
          globalNavigation.fieldLink.getLink({
              text: linkContent,
              class: 'btn btn-primary group'
          })
      }}
  {% endif %}

Output:

image

Somehow when using {{ globalNavigation.fieldLink.text }} on the second button it already has the link text from the previous button stored somewhere displaying the content twice.

Steps to reproduce

  1. Create a hyper link
  2. Use the getLink method to render the link with text override function to for example add an svg or extra span of text.
  3. Render this button another time
  4. The text from the previous button will be displayed aswell.

Craft CMS version

5.1.1

Plugin version

dev-craft-5

Multi-site?

No

Additional context

No response

Fixed for the next release. To get this early, run composer require verbb/hyper:"dev-craft-5 as 2.0.0-beta.8".

Fixed for the next release. To get this early, run composer require verbb/hyper:"dev-craft-5 as 2.0.0-beta.8".

Did this get merged in 2.0.0-beta.8? I don't see the fix when running the command above.

It should be in 077a230 but I can also see the issue with my fix.

Run that composer require verbb/hyper:"dev-craft-5 as 2.0.0-beta.8" command again and that should be sorted.

Fixed in 2.0.0