Using Mustache (Nustache) with traditional ASP.NET (non MVC)
- Download Nustache
- Extract zip file and open solution file.
- If you don’t have MVC3 installed you will get a warning that Visual Studio cannot open the project
- Click OK and continue
- Nustache.Mvc3 project will be grayed out. Right click the solution in Solution Explorer window and add new ASP .NET Application. I named it NustacheWebApplication. This will create Default.aspx page.
- Add new “Template” folder to the solution.
- Copy Index.mustache file from \ Nustache-master\Nustache.Mvc3.Example\Views\Home to the new Template folder.
- Add reference to the Nustache.Core project.
- Open Default.aspx page and add Literal control;
<asp:LiteralID=”LiteralText“ runat=”server”></asp:Literal>
- Open Default.aspx.cs file and add using statements:
using Nustache.Core;
- Then the following code to the Page_Load method:
protected void Page_Load(object sender, EventArgs e)
{
var dataObject = new
{
DoModelPropertiesWork = “Model properties work!“,
DoesHtmlEncodingWork = “<em>Should this be encoded?</em>”,
DoesInternationalCharacterEncodingWork = “Iñtërnâtiônàlizætiøn“,
DoesRussianCharacterEncodingWork = “Привет,как дела“
};
var html = Nustache.Core.Render.FileToString(
Server.MapPath(@”~\Temlates\Index.mustache“),
dataObject
);
LiteralText.Text = html;
}
- You may need to unload Nustache.Mvc3 project from the solution if you don’t have MVC 3 installed before you run the application.
Warning: A non-numeric value encountered in H:\root\home\idenys-001\www\gold-estate\wp-content\themes\technical-speech\comments.php on line 20
Warning: A non-numeric value encountered in H:\root\home\idenys-001\www\gold-estate\wp-content\themes\technical-speech\comments.php on line 21