Is there a way to change color on template merge field text

  • 1
  • Question
  • Updated 1 year ago
  • Answered
In the template below, Is there a way to change the text color of 'Product on Allocation' if 'On_Allocation is true?  Can you embed CSS or HTML?


Photo of Jeffrey Lawler

Jeffrey Lawler

  • 1,454 Points 1k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Try something like this:

{{#On_Allocation__c}}<font style="background-color:red;color:white;font-weight:bold;padding:3px;position: relative;"> -- PRODUCT ON ALLOCATION </font>{{#On_Allocation__c}}
Photo of Jeffrey Lawler

Jeffrey Lawler

  • 1,454 Points 1k badge 2x thumb
Hi Moshe,

Thank you very much for the reply.  I tried the following, simplify it a bit, but there was no change to the test displayed?  Any thoughts?

{{Name}}{{Description}} <font style="background-color:red; color:white;  font-weight:bold; padding:3px; position: relative;"> -- PRODUCT ON ALLOCATION </font> {{Product_Category__c}}
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Jeffrey... do you have "allow html" checked on your template settings?
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
You probably don't won't to use the tag as it is not supported in HTML 5. Use a instead. I will leave it to our fellow web brethren to correct me.

{{Name}}{{Description}} -- PRODUCT ON ALLOCATION {{Product_Category__c}}

Oh, yes, enable "Allow Html" per Jim.
Photo of Jeffrey Lawler

Jeffrey Lawler

  • 1,454 Points 1k badge 2x thumb

I do not think I can "Allow HTML" as this is just the Display Template/Search Template fields for the Search properties on a lookup field.  This is not a Template component field.

 

Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
You can certainly embedd html in a normal template,  but you are using the templates provided to show reference fields.  HTML is not interpreted here.  This looks like a perfect scenario for writing a custom renderer.  JavaScript to the rescue. 
(Edited)
Photo of Poc

Poc

  • 496 Points 250 badge 2x thumb
Hi, how could I put a snippet and invoke it on loan for this case?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
In the Basic menu for the field choose 'snippet' for the rendering property, and enter the name of your snippet in the box that appears.

There are lots of examples of custom field renderers here on the community and in the docs.
Photo of Poc

Poc

  • 496 Points 250 badge 2x thumb
Hi Matt, there's no way to invoke snippet inside template field, right?