How can I use "loadhtml" with a local file path to an HTML-file that is somewhere on my local hard disk?

I want to have a common shared repository of HTML-snippets not belonging exclusively to one template; how can I insert them into my templates?

E.g.: there is a file in “c:\my-snippets\text-1.html”.

How does the “results.loadhtml(…)” - statement have to look like?

Hello Thomas,

You can do this by using a file:// path:

results.loadhtml(“file://C:/localfile.html”);

It works dynamically, too:

results.loadhtml(“file://C:/resources/”+record.fields.contents+“.html”);

I already tried that.
It works for “internal” snippets with “snippets/” as the path part, but when using “file://C:/dir/” as a path, I get a small warning sign that is attached to the scripts name in the list (when switching to preview).
There is no message available that tells what is wrong - it just doesn’t work.

My apologies, it requires 3 slashes. This worked fine for me:
results.loadhtml(“file:///c:/data/submitfile.html”);

If you have a warning sign in preview, it’s probably because either the selector is wrong (you’re trying to put the snippet in an element that doesn’t exist, such as a wrong ID), or perhaps the file doesn’t exist on the drive? Like I said, the above works perfectly for me with a simple selector on p.contents , where .

Thanks! It was the third slash!
The warning-sign was shown, because the referenced HTML-file could not be found.
Now it works like a charm!

further possibilites (without the prefix “file:///”):

results.loadhtml(“C:/PLANETPRESS/test.html”);

results.loadhtml(“C:\PLANETPRESS\test.html”);