HTML templating solution for both ASP.NET MVC and browser? - javascript

I'm trying to find an HTML templating solution that will work both on my ASP.NET MVC application (.NET 4, IIS 7.5) and in the browser. The reason is to the the same code to render HTML both on the server (performance, outputting to mobile, etc) or on the browser (refreshing data via AJAX). This is not a new problem, but I am wondering if current technology trends have changed the answer.
A couple of ideas I am considering:
Use mustache templates with are available in both
JavaScript and .NET.
Use a port of the Razor View Engine to
JavaScript like considered in Javascript + Razor == Jazor?.
Take a position like Micro Templates Are Dead... forget about it and
just use JavaScript (IronJS?) and the DOM (jsdom)
ASP.NET MVC View Engine Comparison looked relavent, but there is no mention of mustache.
Update: The client-side templating throwdown: mustache, handlebars, dust.js, and more from LinkedIn Engineering rates mustache in it's top four, with it being the only one with native .NET rendering (vs requiring server-side JavaScript to render on the server).

I would highly recommend mustache for your application. You have already mentioned abt the fact that it has a server side rendering engine and also a strong community backing. Apart from this the major reason why I would recommend mustache is for Performance of the templating engine. I have played around with the same and none of the other JS templating solution could match the performance of mustache.
What I would like more is documentation around the library but you should be able to work around this.

I have done that using Spark view engine, it is quite good with the template where you can use it from .net and js.

Related

HTML template engine with both ASP.net core and JS support

Is there any HTML templating engine, which can be ran with ASP.net core at the server side and with JS on the client side/browser, and produce same HTML output with a level of consistency?
The benefit will be to have the flexibility in rendering, either in the client side or in the server side.
After some research, I've found the Liquid templating engine to be available both in .net and JS. It is available across many more languages and frameworks.
The .net library is- https://github.com/sebastienros/fluid
The JS library is- https://liquidjs.com/
The "Orchard core" project by Microsoft is also using the "Fluid" library. And there is also "Scriban" .net library with liquid support.
I've not tested them yet in a project. So, no concrete idea at that front. Hope this may help someone.

Which editor to use for coding dynamic web pages

I am new to web development and I see it is very common to print HTML syntax from some server side script which is typically written in python, php, perl etc.
Now, normally all editors have some features which can help with syntax checking of the HTML as the programmer is writing them.
However, if the HTML code is emitted from a print statement, how can HTML syntax checking be done.
For example
the server side python script generating an HTML form can be like
print("<td><input type="file" name="upload_file" />")
Here the ending tag
</td> is missing. Is there an editor which can warn about this. Otherwise, how do the programmers deal with it.
You can't display this code using python. If you want to create a server, you will need to look for the development of the server side (these are the three most used):
Flask
Django
Tornado
Also, you can check more web frameworks here: https://wiki.python.org/moin/WebFrameworks
use sublime, its light weight and have lots of features.
For any non-trivial work it's best not to embed HTML (or any other language) in your Python code. Use a templating engine such as jinja2 or one of the others available. Most Python web frameworks support integration with at least one templating engine.
Separating your code and markup by using a templating engine makes your code easier to maintain. In particular, files for templating engine code are essentially HTML with some additional markup to allow for variable substitution, looping etc and so your editor's HTML syntax highlighting will work on them.

Vuejs as an HTML templating engine

I'm looking for a front-end HTML templating engine and I was wondering if Vuejs has this functionally built into it. If not, can someone recommend me a templating engine?
All I want to do is create HTML pages which derived from a master page.
Thanks
I've used Mustache and have found it great - easy to use and fast. Check it out here: https://github.com/janl/mustache.js/

Using js scripts in handlebars? [duplicate]

I'm totally new to js template engines. Handlebars seems to be the popular choice. I don't dislike the syntax for doing conditions, loops and so on, but since I'm perfectly capable of and feel more comfortable using plain old js and I'm not planning to let anyone who doesn't know js touch my templates, I'm asking if Handlebars supports this.
Of course the most popular choice isn't always the best. I'm more of a Mootools guy and jQuery drives me crazy(great library, just not for me). So if Handlebars was jQuery of template engines, what would be Mootools?
One of the central ideas behind handlebars and mustache is they are LOGICLESS by design and intention. They can not now, nor will they ever allow or recommend you embed raw JS in your templates. Some say this is a better design. If you want embedded javascript, almost every other traditional templating engine, such as _.template or jade or EJS is based on (or at least supports) the idea of embedded JS code snippets.
Sorry to resurrect a old issue here. If you have to use handlebars or it's not feasible to change your templating library you can use Helpers from the Handlebars library.
https://handlebarsjs.com/guide/expressions.html#helpers
Registering a helper in handlebar can be a walk around to what you are trying to do. See this link for a complete example: Registering handlebars helpers with node does absolutely nothing

Is there any viewengine exists for PHP so my asp.net mvc site has PHP as language for my VIEWS?

Now I'm working with asp.net mvc, it's good framework. But, in future, I want to work with php or ruby to develop views for my asp.net MVC site.
I am not sure what this concept is called but I know something exists.
I think, I must generate pages with clear html, javascript and use json for transfer data. What patterns I can use and how implement navigation?
Any other thing exists to do this?
Well in case if you wish to create your VIEWS for asp.net MVC site using PHP code you can opt for PHP View Engine.
It allows you to write ASP.NET MVC views in the PHP language.
http://phpviewengine.codeplex.com/ is link you can follow.
This way all your ASP.NET code for Controller And Model will be intact and you can create your views in PHP.
I hope this is what you would be looking for.
Another view engine for php is sharpy I hope this also could be one for you. On top of that I am not sure anything is there for ruby.
I want maximum unbounded from C# for quick implement on server-side
php or ruby.
Based on this comment, your only option to have server-side code return data in a standard format (like JSON) and rely heavily on client side templating to turn data into HTML.
LinkedIn had a similar problem. They had three different server side technologies and had a hard time re-using components. There is a good write-up about their experience here and a pretty through comparison of different templating technologies here.
Consider using Mustache (http://mustache.github.com/) as your view engine. It will allow both PHP, .NET and JS to consume the views and render with server-generated content. Nustache has a library for ASP.NET MVC as well to make the transition easy.

Categories