0

We are a little confused about pre-compiling a template. for example:

Is it possible to store the template variable in say a database and then just retrieve it and call

string source =
@"<div class=""entry"">
  <h1>{{title}}</h1>
  <div class=""body"">
    {{body}}
  </div>
</div>";

var storedTemplate = Handlebars.Compile(source);

Once we have the compiled template then store the variabe storedTemplate in a database. Then whenever we need it, just retreive from Database and pass the required object.

//retrieve template
var retrievedTemplate = retrieve storedTemplate from datase

var data = new {
    title = "My new post",
    body = "This is my first post!"
};

var result = retrievedTemplate (data);

But we cannot get this to work and wonder why.

4
  • @D A Hi, we tried it but there is no such command as Precompile! Commented Oct 15 at 18:03
  • You’d need to use JavaScript (handlebarsjs.com/api-reference/…) to generate the precompiled string and send it back to your C# code. Indeed it is not in the Handlebars.Net library. Commented Oct 16 at 5:20
  • @D A The question was for Handlebars.Net! Commented Oct 16 at 20:14
  • Sure, but I offered u an alternative solution. Commented Oct 17 at 11:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.