How do I override a lookup/reference field link in a template?

  • 1
  • Question
  • Updated 3 years ago
  • Answered
  • (Edited)
I'm trying to create a link that takes a Skuid user to a specific page when they click on a person's name. I don't know that I necessarily want to override pages, as this will require more info than just the ID of the person's Contact record. I figured I would just make a template with an HTML anchor tag that goes to another Skuid page. Here's what my template field says:
<a href="/apex/ui?seid={{Student_Enrollment__c}}&page=StudentDetail">{{Student__c}}</a>

But here is what it looks like when it renders:

Obviously something funky is happening with how the HTML and merge fields are interacting. What am I doing wrong?
Photo of Peter Bender

Peter Bender, Champion

  • 6,296 Points 5k badge 2x thumb

Posted 6 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 53,784 Points 50k badge 2x thumb
Official Response
Short answer: wrap Student_Enrollment__c in triple mustaches / curly braces, and Skuid will output the plain, unformatted value of the Student_Enrollment__c relationship field:

<a href="/apex/skuid__UI?page=StudentDetail&seid={{{Student_Enrollment__c}}}">{{Student__r.Name}}</a>

Long Answer: whenever you use two curly braces around a field in a template, such as "{{Student__c}}", Skuid will look at your Model to see if there's a corresponding field, and if there is, it will use that field's metadata to try to render the raw data in an appropriate format. Examples:

(Datetime) 2012-12-31 14:05:08.003Z ---> 31/12/2012 14:05 (in Britain)
(Lookup field) 0030000004754AAA ---> link to Jack Black's Contact record, with Jack Black as the link text

So, for your case, when you tried to put "{{Student_Enrollment__c}}" inside of an HTML link, you were actually getting a double link, because Skuid was trying to render a link to the Student_Enrollment__c record inside of your link.

But, when you use triple mustaches, Skuid just spits out the raw data, not doing any rendering at all. Compare:

{{{Student__c}}} ---->

{{Student__c}} ---->
<a href="/0030000004754AAA">Jack Black</a>