Handlebar expression, within handlebar expression

Is it possible to use a handlebar expression to display a block of text, which itself contains a handlebar expression that would be rendered properly?

Think that I want to have a variety of custom paragraphs (in a data file) that all contain {{name}} in them so that they can appear personalized to who they are being sent to?

Is something like this possible? or when are handlebar expressions evaluated? Could I load the paragraph with a script before they are evaluated to have this work?

Trying to think of ways to make this type of content as dynamic as possible

This is possible as we use it ourself in our templates. An example is:

{{ MyCustomFunction (MyCustomFunction2 param1_2 param2_2) param1_1 param1_2 }}

You must use the () for the 2nd part. And MyCustomFunction and MyCustomFunction2 are registered properly of course.

@dvdmeer thank you for the confirmation!

Would it be possible to get a sample design containing this? I’m not used to doing the more complex usage of handlebars and a hands on example I could look through would be incredibly helpful.

Hi,

I will leave that to someone from OL as unfortunately I do not have time to create a sample design.
Do note that you can find a lot of examples at the blog posts that have been written: OL Resource Center (uplandsoftware.com)

1 Like

@SamSorenson it sounds like you’re looking for the partials feature.

As a first step you would add your custom paragraphs with {{name}} expressions to a Handlebars file in the Snippets resource folder. Let’s say that file is called “paragraphs.hbs”. In your section you can then add {{+ paragraphs}} to render the HTML and Handlebars expressions contained in that file.

Note: In Connect 2022.2 or earlier you would need to use the more verbose syntax {{+ snippets/paragraphs.hbs}} instead.

You can also make the reference dynamic. Suppose you have two Handlebars files, “paragraph1.hbs” and “paragraph2.hbs”, and a data field with the value “paragraph1” for one record and “paragraph2” for another. In your section you can then add {{+ (fieldName)}}. The parentheses ensure that “fieldName” is evaluated as an expression rather than a literal.