Can I use the handlebars to build my components for a website, if yes what are the limitations of using Handlebars over Sightly?
Is it advisable to create my own handlebar scripting engine or I can use the one being used for SCF? If I use AEM Communities Handlebars Scripting Engine is there any licensing complication that I need to be aware of?
You can use handlebars to build your component. One key difference between handlebars and HTl (Sightly) is that HTl is server-side templating while handlebars can be used on both serverside and clientside.
Related
Is it better to use html template (and then html import) to create web components or to use template string? What are pros and cons of these methods?
Using html template files is better for reuse: the same file can be used in different web components. Also they are better displayed in most IDEs as they are recognized as full HTML code.
Using template strings is faster (inline). They don't rely on HTML Imports which is not adopted by every browser vendors. Also you can use template literals to insert directly value of JavaScript variables in the DOM.
Actually there's no much diffrences because there's a workaround for every differences list above (i.e. you can reuse template strings if you save them as text file, or you can load html templates withour HTML imports).
I want to implement my own Html.EditorFor by creating a template in Views/Shared/EditorTemplates.
I would like to start with the vanilla template and change this to my needs.
But where can I see the default editor-for templates of ASP.net MVC?
What I try to do: get my own css classes (uikit instead of bootstrap) and a more simple way of adding validation with jquery.validate (using required attribute, for example).
Something that would work like the CodeFormatter package does for regular HTML, but with Spacebars would be awesome!
There appear to be some plugins for Handlebars, which Spacebars is built off of.
Meteor ships with a templating language called Spacebars, inspired by Handlebars. It shares some of the spirit and syntax of Handlebars, but it has been tailored to produce reactive Meteor templates when compiled.
You can search on Package Control for Handlebars; it looks like this one is pretty popular.
Really old, what I did was download https://github.com/victorporof/Sublime-HTMLPrettify and use this in Sublime Text. Open the preferences for it and enable handlebars indentation with
"indent_handlebars": false, // e.g. {{#foo}}, {{/foo}}
We're starting to use Handlebars for the view layer in some of our projects. We are starting to hit a crossroads between two ways of doing some templating. I've been using partials to handle the templating & having small HTML templates like:
<p id="{{name}}">
<label for="{{name}}Input">{{text}}</label>
{{#if info}}
<small>{{info}}</small>
{{/if}}
<textarea name="{{name}}" id="{{name}}Input"></textarea>
</p>
Another developer feels that we shouldn't be using partials for this & instead we should be creating helpers for this.
I can see helpers being easier to handle input parameters (as I'm currently using some form of "include" helper to include these partials with some extra variables). But it doesn't sit right with me that you are writing HTML into strings in code - I don't think you're separating your concerns properly there. We are also using Handlebars in Java (via [Handlebars.Java][2]), so again your HTML is very much in compiled code - not in simple to edit view files.
Is there a generally accepted way to handle templating in Handlebars? Partials or Helpers or is there something else I don't know about?
Well, first you need to understand that partials are very different in handlebars.js opposed to handlebars.java
In handlebars.js, you declare your own partials and call/name them whatever you want in your controller (usually) and then call them within your view. In handlebars.java a partial is defined in your view and is essentially just an include taking a path attribute. Includes are generally integral to most projects and I don't think there's any benefit to dropping such an important piece of functionality.
Also, I've seen the mentality of "use helpers for everything" in many handlebars.js apps and it is becomes difficult to maintain very quickly. Helpers are a great feature but they should be used sparingly. Whenever possible, use the built in helpers and try structuring your data in a way that you doesn't require additional abstracted logic.
Looking at your example, i think thats exactly the correct useage of partial.
I want to do some preprocessing on my views before they are parsed by the Razor template engine. The only way I found so far is by extending the RazorTemplateEngine class and overriding the CreateParser method, where I can return a custom parser that does the preprocessing before calling the base parser.
Now my problem is - how can I make Razor use my custom template engine?
I don't know if that will work for you but it should :)
try to add
#inherits YourRazorTemplateEngine
in the head of your views.
for more information look at this page