Referencing Text Scripts in a snippet

I’m trying to use a snippet in my email context. My snippet is using code I had in the context directly but had to move in a snippet. So, in my snippet, I have reference to text scripts (@myExample@).

I’m loading my snippet using a script with loadHtml(location) into an element in my context based on the ID.

When I look at the design view, I don’t see my snippet, and when I look at the preview or live view, I see my snippet as is, with all the @textScript@. How can I make it so that the text scripts actually load sata from my data model ?

Thanks

1 Like

Hello Dupras,

You could achieve that like this:

var mySnippet = loadhtml('snippets/snippet.html');
mySnippet.find('@value@').text(record.fields['somefield']);
results.html(mySnippet);

Or

var mySnippet = loadhtml('snippets/snippet.html').toString();
mySnippet = mySnippet.replace('@value@', record.fields['somefield']);
results.html(mySnippet);

The latter typically shows a better performance.

A third option would be changing the order of the scripts so that the text script for the @textScript@ is executed after the script that loads the snippet. This assumes you have two scripts. Keep in mind that scripts are executed in the order they appear in the Scripts panel (from top to bottom).

Hope this is of some help,

Erik

The third option is probably the best since I have multiple references to text scripts in my snippet.

Altough, I realize now that my dynamic table is no longuer showing all of my detail records, but only the first one.

Hello Duprass,

I`ve you’d like some further assistance you can open up a ticket with us at Document composition and automation | Upland Objectif Lune so we can have a better look and properly diagnose your issue.

Thank you!

Francis C