0

I wrote up a site using Mustache to template it. Right now though, the template is embedded in the page, which defeats the purpose of using the template since I'll need to copy it to any other pages that need it.

I read that it's possible to store the template in an external page, then use Ajax to load the template when needed, but this is for a school project, and I'm not yet at the point where they want us using Ajax.

Is it possible to have the template externalized without the use of Ajax?

Ideally, I'd like to have the following setup:

...
PageUsingTemnplate.html
AnotherPageUsingTemplate.html
...
Template.html
  • If you use some kind of templating engine like Jade, Thymeleaf or JSP etc. you can statically include one file in multiple other files. – Traubenfuchs May 12 '16 at 10:19
1

You can use Partials

Partials begin with a greater than sign, like {{> box}}.

For example, this template and partial:

base.mustache:

<h2>Names</h2>
{{#names}}
  {{> user}}
{{/names}}

user.mustache:

<strong>{{name}}</strong>

Can be thought of as a single, expanded template:

<h2>Names</h2>
{{#names}}
  <strong>{{name}}</strong>
{{/names}}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.