1

I have a twig template for a custom block, I want the entire block to be wrapped in a link. I'm using the link field, but I'm not sure how to get the url from the field within the twig template. This seems like it should work, but doesn't:

{{ content.field_link.0.getUri() }}

I've looked at url() and path(), but they are dealing with routing, so I don't think that's what I'm looking for.

Note, I would like to use either external or internal links in the field.

1

Ah, I was missing the ['#url'] part of the array. In order to get the url from the link field I called:

{{ content.field_link.0['#url'].getUri() }}

I do miss the ability to copy-paste from dpm().

  • If you miss dpm() and you haven't found devel's kint submodule, you should look into it. – acrosman Jul 19 '16 at 15:00
  • I use kint, but it doesn't give me an easily copiable string to "dig down" to variable – icicleking Jul 19 '16 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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