1

I want to do something that's perhaps connected to the id so that if the title/slug updates, then I don't have to hunt anything down in entries across the CMS.

Something like this maybe? [Link to an entry](/section#entry:10725)

  • For example, highlight text in a rich text area and link to an entry? – Damon Aug 10 '17 at 4:08
  • Yeah, how do I get the url like that based on an id? – Ryan Aug 10 '17 at 23:44
  • I don't think I quite follow. If you highlight text (redactor for example) Craft will convert that for you. Just highlight the text and chose link -> entry Which will look something like this in the markup: http://mysite.com/#entry:2 You can change the #entry:2 title, slug - whatever and everything will still work since Craft is linking to the entry. It doesn't care what you call it. – Damon Aug 11 '17 at 1:50
  • The field isn't Rich Text; it's just plain text, and the template code uses the |markdown filter. I know how to make a link in markdown [text](url) but I'm wondering how to fill in the url dynamically based on id. http://mysite.com/#entry:2 doesn't work because it prints exactly that string out as the url. I want #entry:2 to convert into the uri for that entry on output. – Ryan Aug 11 '17 at 12:24
2

I just figured out how to do this. It was vexing me!

Anyway, Craft is awesome and has provided support for Reference Tags.

Write your Markdown like this:

[link text]({entry:20})

Here's the Twig:

{{ entry.markdown|parseRefs|markdown }}

Reference Tags support more than just entries, but this was the bit that I needed.

| improve this answer | |
  • Wow! Excellent answer @plaintxt! This works, and I learned something new about Craft. Well done! – Ryan Mar 13 '18 at 0:30
  • 1
    Also, it's pretty cool that you can get all kinds of information about an entry using Reference Tags. I used this yesterday: [{entry:40:title}]({entry:40}) Which resolves to an <a> tag populated with the entry's title and url. – plaintxt Mar 13 '18 at 13:01

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.