I have an article in my template with source a remote html.
I need to change the source when one of the field value changes. How I can access the source using a script and change the source to another remote html?Thank you
I have an article in my template with source a remote html.
I need to change the source when one of the field value changes. How I can access the source using a script and change the source to another remote html?Thank you
Hi Kirshna,
You can achieve this by either scripting or utilizing Handlebars partials. The latter allows you to input simple expressions directly into your sections, which might be worth considering for your setup.
Here are a few examples:
{{+http://localhost:1880/cms/policies/05501-building.html}}
ref
, adding a file extension:{{+ (concat 'http://localhost:1880/cms/policies/' ref '.html')}}
{{+ (concat @parameters.cms ref '.html')}}
I hope this helps!
Erik
Thanks Erik.
I didn’t quite get this.
My scenario:
I have two remote html in snippets folder in Resource pane. Let it be “xyz.rhtml”. and “abc.rhtml”
Template is loading the remote html using article tab.
article class=remote source=“snippets/Email/xyz.rhtml” ></article
I have a data field “Id”. I have to dynamically load remote html depending on the value of “Id”.
Could you please help me with this scenario?
(Right now I used two article tag and gave different id’s. Used a conditional script to show /hide one of them. This loads both snippet in design mode.)
Thank you
When dealing with dynamic snippets, it’s often easier to load the content using a script and the loadhtml()
command by passing the URL directly. Capture the response in a variable and then write this to your <article>
element replacing its entire content by passing the variable in the html()
command. See the example below.
There are several methods to construct the path in your script. The following demonstrates a more traditional approach by combining the base URL with the value from your “Id” field:
// Selector: .remote
let url = 'http://localhosts:1880/cms/' + record.Id + '.html';
let content = loadhtml(url);
results.html(content);
I have attached a sample template which loads the data from a local snippet.
Hope this helps,
Erik
Sample data:
[
{
"Id":"05501-building"
},
{
"Id":"03910-travel"
},
{
"Id":"05501-building"
}
]
dynamic-snippets-script.OL-template (8.6 KB)
I got it. Thanks Much Erik.