I'm using markojs for my emails templates but now we are moving these templates inside our database to edit them online. We still need to use marko to keep our full HTML structure and variables behavior aswell.
I've found 2 ways to get templates as string like renderSync() method but it need the template to exist as file before or with compile() but I don't know how to make it work with variables handling.
You can use Marko's
loadmethod to compile templates and get back the template instance which you can then render to get the final HTML:You probably don't need to pass any custom
compilerOptionsand can omit the last argument.Even though your template doesn't exist on disk, you still need to pass a
templatePathto a real directory with a dummy.markofile. For instance you could do this:The
templatePathis used for two purposes:requirecache. If you request to compile the same filename multiple times, you will get the original compilation. This might mean you need to purge the require cache when a template is edited:delete require.cache[templatePath];templatePathallows those tags to be discovered.