Posted on 28th March 2013One Response
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.
Comments
Fatal error: Uncaught TypeError: Unsupported operand types: string - int in H:\root\home\idenys-001\www\gold-estate\wp-content\themes\technical-speech\comments.php:20 Stack trace: #0 H:\root\home\idenys-001\www\gold-estate\wp-includes\comment-template.php(1554): require() #1 H:\root\home\idenys-001\www\gold-estate\wp-content\themes\technical-speech\single.php(28): comments_template() #2 H:\root\home\idenys-001\www\gold-estate\wp-includes\template-loader.php(113): include('...') #3 H:\root\home\idenys-001\www\gold-estate\wp-blog-header.php(19): require_once('...') #4 H:\root\home\idenys-001\www\gold-estate\index.php(17): require('...') #5 {main} thrown in H:\root\home\idenys-001\www\gold-estate\wp-content\themes\technical-speech\comments.php on line 20