2

I've created a custom theme override for views-view-fields.html.twig to views-view-fields--about-us.html.twig which is a listing of members on a site and the code I've used is as follows:

{{ fields.field_photo.content }}
<div class="caption">
  <h4>{{ fields.title.content }}</h4>
  <p class="em">{{ fields.field_job_title.content }}</p>
  <a class="btn btn-primary btn-block" href="{{ path }}">{{ 'Learn More'|t }}</a>
</div>

However, when I view the page, the only thing not working is the link to the content. The "Learn More" is supposed to go to each persons full bio, but instead, all that it links to is the current page/view.

Is {{ path }} not the correct code to use as the URL? I've tried numerous other solutions that I thought I found on this site for it but it either doesn't work or breaks my site.

EDIT 1:

When I try No Sssweat's answer from below, which I had tried before, I get the following issues:

Extra bit of code is printed below the button like the image below: Extra Code Beneath Link

And, this is what the code looks like when you hover over the link: Hover URL

1

1 Answer 1

3

In Views, you need to add Path as a field, which you probably already have, and you can print it like this:

{{ fields.path.content }}

so

<a class="btn btn-primary btn-block" href="{{ fields.path.content }}">{{ 'Learn More'|t }}</a>
7
  • See Edit 1 in the main post as to what happens when I try this. Commented Jan 24, 2017 at 14:11
  • That's what the complete URL is...nothing comes after it. That's the complete URL when hovering over the green button and the extra ">Learn More is printed under the button. Commented Jan 24, 2017 at 14:20
  • @ACanadianCoder Sorry, I initially thought you were inspecting element with your browser. Turn off twig debug and flush the cache, see if that fixes it, I'm confident that it will.
    – No Sssweat
    Commented Jan 24, 2017 at 14:21
  • Ok, I've done that and still doesn't work properly. But, I can see what the issue is. This is what the code looks like: <a class="btn btn-primary btn-block" href="<a href="/people/persons-name" class="btn btn-primary btn-block">Learn More</a>">Learn More</a> It looks like it's repeating the link inside the href. Commented Jan 24, 2017 at 14:26
  • 1
    You know what, I think it's cause I have ReWrite Results being used for the Path. If I just use {{ fields.path.content }} in my twig template without the surrounding code, everything works properly then. Or I could use the code you gave above and just remove all the content I put in the Rewrite Results portion for it to work that way. Commented Jan 24, 2017 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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