Render double curly-brackets inside handlebars partial - handlebars.js

How do you force handlebars.js to ignore (and not render) templates?

It's possible to escape the line with backslash
\{{>partialName}}
It's not mentioned in the documentation, but a look at the source-code documentation revealed this technique.

HTML entity might be a solution if you just wang to display your brackets. Try { and }.

Related

HTML tags (i.e <p>) inside my angular brackets {{}}

I'm working in an angular app where the JSON documents i'm getting includes several object. But while fetching the posts contents it also includes the HTML tags (i.e <p>) inside my angular brackets {{}} the problem here is i want only the contents not the HTML tags. Either give me a solution to get rid of that or tell me how to use html tags inside {{<p> hello <p>}} . I want to get an output of angular to show the paragraphed "hello" instead of <p>hello<p>.
Give me a solution to ge an output as hello instead of <p>hello<p>
thanks in advance!
Thanks for the response!
I Used the angular binding ng-bind. That working fine for me. I've used
<p ng-bind-html="post.name"></p> . Now the problems solved :)
I'm not sure if there is a 'best practice' solution for this, I don't think angular is currently handling this. Try using a function that strips the html tags like this:
{{stripInput(inputObject)}}
stripInput(html) {
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || "";
}
credit to this post. Some other good answers are there if this doesn't work :)

Not sure what tool/language will use "curly brace" syntax in asp.net web form page

I am responsible for maintaining a asp.net web form page(not mvc, not razor), and found some curly brace syntax I am not familiar with.
The following is the example,
{{#CurrencyRates}}
<div class="{{^IsLast}}tzsg-padding-bottom-xl tzsg-border-bottom-light{{/IsLast}} tzsg-margin-top-xl"></div>
{{#HasWhatsIncludedRateLevel}}
As you can see, those curly brace even shows in css attribute.
I double that it may be angularJS syntax, but can not find any related angularJS files or syntax, like ng-app.
My question is: what tool/language it is.
Thank you.
Updated Status:
Thanks for Arindam Nayak's hint, and I found out it is using mustache.js.

How do I style a inc via html object with css?

I was searching for a way to use includes without server side assistance and found the object .inc method here.
Example: <object name="foo" type="text/html" data="foo.inc"/></object>
Which works great, except I can't style anything inside the .inc file without linking the style sheet within it.
Is there a way to do with the parent html file? like: object:foo #innerelement {}
That is my thinking anyways, like there should be some sort of notation for this.
If I recall correctly, the answer is no because this method is implemented similar to how an iframe tag would work.

programmatically remove all html and inline formatting

I have taken over a code base and I have to read in these html files that were generated by Microsoft Word, I think so it has all kinds of whacky inline formatting.
is there anyway to parse out all of the bad inline formatting and just get the text from this stream. I basically want a purifier programmatically so I can then apply some sensible css
You should use HTML Tidy - it's uniquitous when it comes to cleansing HTML. There's an article on DevX that describes how to do it from .NET.
in the end i just wrote a small class that did a bunch of find and replaces. not pretty but it worked.

JQuery's $ is in conflict with that of StringTemplate.Net in ASP.Net MVC

I am exploring ASP.NET MVC and I wanted to add jQuery to make the site interactive. I used StringTemplate, ported to .Net, as my template engine to generate html and to send JSON. However, when I view the page, I could not see it. After debugging, I've realized that the $ is used by the StringTemplate to access property, etc and jQuery uses it too to manipulate the DOM. Gee, I've looked on other template engines and most of them uses the dollar sign :(.
Any alternative template engine for ASP.Net MVC? I wanted to retain jQuery because MSFT announced that it will used in the Visual Studio (2008?)
Thanks in Advance :)
Update
Please go to the answer in ASP.NET MVC View Engine Comparison question for a comprehensive list of Template engine for ASP.NET MVC, and their pros and cons
Update 2
At the end I'll just put the JavaScript code, including JQuery, in a separate script file, hence I wouldn't worry about the $ mingling in the template file.
Update 3
Changed the Title to reflect what I need to resolve. After all "The Best X in Y" is very subjective question.
You can of course move your js logic into a .js file. But if you want it inline with your StringTemplate views, you can escape it using the \$ construct.
In addition, you can simply use the jQuery("selector"), instead of $("selector") construct if you want to avoid the escaping syntax.
Here's a good article on using StringTemplate as a View Engine in MVC.
There's also an accompanying OpenSource engine, along with some samples.
Also, as mentioned above, you can modify your Type Lexer. (make it an alternate character to the $).
I would highly recommend Spark. I've been using it for awhile now with jQuery and haven't ran into a single issue so far.
JQuery can be disambiguated by using the jQuery keyword like this:
jQuery(
instead of this:
$(
I would consider this a best practice. It eliminates any possibility of clashing with another library, and makes the code more readable.
Perhaps jQuery.noConflict will work for you
Have a look at the mvccontrib project. They have 4 different view engines at the moment which are brail, nhaml, nvelocity and xslt.
http://www.codeplex.com/MVCContrib
In case you want to stick with StringTemplate (ST) see this article from the ST wiki. You may also change the behaviour totally by editing Antlr.StringTemplate.Language\DefaultTemplateLexer.cs and replacing the "$" with what you want.
I really like the syntax in Django, so I recommend NDjango :)
Have you tried $$ or /$ to escape the dollar signs in string template? I'm not sure about ST specifically but thats how most template engines work.
As for other templating engines, I really loved nVelocity when I used it on a project.
JsonFx.NET has a powerful client-side templating engine with familiar ASP.NET style syntax. The entire framework is specifically designed to work well with jQuery and ASP.NET MVC. You can get examples of how to build real world UI from: http://code.google.com/p/jsonfx-examples/
I've been using ANTLR StringTemplate for ASP.NET MVC project. However what I did was to extend the StringTemplate grammar (template.g) to recognize '%' (aspx.template.g) as delimiters. You can find these files if you download the StringTemplate.net version. I generated the corresponding files: AspxTemplateLexer.cs, AspxTemplateParser.cs, AspxTemplateParserTokenTypes.cs and AspxTemplateParserTokenTypes.txt.
In addition I altered StringTemplateLoader.cs to recognize the extensions .aspx and .ascx which Visual Studio recognizes. This way I am not stuck with the .st extension and clients don't know the difference.
Anyway after rebuilding StringTemplate I have the behavior that I want. What I like about StringTemplate is that it does NOT permit ANY code to be embedded in the template. It looks like Spark like the default ASP/MVC template is code permissive which makes the templates less portable.
I would prefer is "<%" and "%>" as delimiters but unfortunately the ANTLR grammar seems somewhat difficult and fragile to alter unless someone else has done it. On the other had StringTemplate has a great support community and a great approach to separation -- which is the point of MVC.
You could try jsRepeater.
You may need this .NET Template Engine. If you wish to use '$' character, simply use '$$'. See the code below:
{%carName = "Audi R8"/}
{%string str = "This is an $carName$"/}
$str$
$$str$$
the output will be
This is an Audi R8
$str$
If I understand StringTemplate version 4 correctly you can define your own escape char in Template (or TemplateGroup) constructor.
Found Mustache to be the most fool-proof, easiest-to-use, lightest full-featured templating engine for .Net projects (Web and backend)
Works well with .Net 3.5 (meaning it does not need dynamic type and .Net 4.0 to work for mixed type models, like Razor).
The part that I like the most is ability to nest arbitrary IDicts within and have the engine do the right thing. This makes the mandatory-for-all engines reboxing step super-simple:
var child = new {
nested = "nested value"
};
var parent = new {
SomeValue = "asdfadsf"
, down = child
, number = 123
};
var template = #"This is {{#down}}{{nested}}{{/down}}. Yeah to the power of {{number}}";
string output = Nustache.Core.Render.StringToString(template,parent);
// output:
// "This is nested value. Yeah to the power of 123"
What's most beautiful about Mustache is that same exact template works exactly same in pure JavaScript or any other of 20 or so supported languages.

Resources