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 ?
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).