In handlebars how can I say for example:
{{#if view_type == "medium"}}
// Do something
{{/if}}
Not simply :
{{#if view_type}}
// Do something
{{/if}}
Im am using it in NodeJs
Im looking for solution without registerHelper()
There's no solution without a new helper. What I would suggest you is to switch from handlebars to Swig, which, the syntax, is pretty similar.
http://paularmstrong.github.io/swig/docs/
It is easily implementable.
If you are trying to do an IF I guess you are at the beginning of your project so it could be an option.
Related
This works fine:
<h1 class="uk-heading-line uk-text-center"><span>{{processNameUpper}}</span></h1>
{{> process-BUF-labels}}
but now I also want to use a dynamic partial naming like so:
<h1 class="uk-heading-line uk-text-center"><span>{{processNameUpper}}</span></h1>
{{> process-{{processNameUpper}}-labels}}
But sadly this is not allowed.
Is there any way without a complicated partial expression function?
And I really want to have the labels files in separate files.
I've been working with pug/jade a little bit and now I'm trying to build the same project using handlebars.
I have this iteration that renders a few options:
<select id="myselect" name="myselect">
{{#each categories}}
<option value="{{id}}">{{title}}</option>
{{/each}}
</select>
A bit further down the code I need to render some items dynamically based on the selected item from myselect.
Any idea how I can grab it dynamically? Basically the same way like onchange() works in plain javascript.
When you use any kind of tempting engine (handlebars, jade, ejs, etc). You cannot bind data after the response sent to the client. You have to write some client side javascript code to achieve that.
As an alternative you can use handlebarjs on client side. Follow this link
But this may need to be used carefully, since you are using the same template engine on your server side.
Hey so my problem is probably simple as I am brand new to ember and ember-cli, from what I understand you simply edit an applications HBS template containing the html, IE.
app/templates/settings.hbs
however my problem is that when I edit one of these files and restart the entire stack, no change is reflected - furthermore I'm basically just trying to create some minor changes to an already created stack by entering an if conditional to find the controller name and display content if it matches what im looking for,
for example
{{#if controller.name == "settings"}}
// diff lis
{else}
// normal lis
{#endif}
most importantly here, any changes I make at all to the HBS template does not seem to be reflected live, any idea why?
In addition to #Oren answer, if you're using ember 1.10 you can take advantage of handlebars subexpressions and write your own eq helper which could be used in more situations. For instance:
Ember.Handlebars.registerBoundHelper('eq', function(left, right) {
return left === right;
});
And then in your template
{{#if (eq name "settings") }}
// diff lis
{{else}}
// normal lis
{{/if}}
// ...
{{#if (eq something otherstuff) }}
// show this
{{else}}
// show that
{{/if}}
Live sample http://emberjs.jsbin.com/mezoxiqavi/1/edit
Handlebars does not have an equality helper in the form that you have posted. (See this list for a list of all of the built in helpers.)
Instead, what you need to do to make your code work is create a property on your controller:
IsNameSettings: function(){
return this.get('model.name') === 'settings';
}.property('model.name');
And change your template to use this property (note that you also have {{/endif}} which needs to be changed to {{/if}} [see the link above]):
{{#if controller.IsNameSettings}}
// diff lis
{else}
// normal lis
{/if}
See whether after changing your handlebars template to valid syntax as I described results in the page live updating when you are waiting for a live reload. Confirm that after saving these changes, you see output from ember-cli indicating a successful build. Check for output in the terminal along the lines of:
version: 0.1.12
Livereload server on port 35729
Serving on http://0.0.0.0:4200/
Build successful - 8891ms.
I am using EJS with Node JS. Also I am using i18n-node-2 for multilingual site.
In my view I have a statement like this:
<h3 class="panel-title"><%= i18n.__("Business Card maker wizard - Step %s", "<span id='bcMakerStep'>1</span>") %></h3>
Here I want to output<span id='bcMakerStep'>1</span> as it is.
But the EJS is transforming it into Business Card maker wizard - Step <span id='bcMakerStep'>1</span> so that is displaying as it is.
Is there any way in EJS to print the tags as it is?
PS: I have tested without EJS to check whether i18n-node-2 is doing that, but it is not but EJS.
I just found out the answer,
If we use <%- instead of <%= it will print characters unescaped.
Thanks to Jakub Oboza at https://stackoverflow.com/a/10330401/721597
im new to node and i've searching ways to add dynamic data into html files, like php:
<?php echo $data; ?>
i've found that jade seems to be the exact way for node, but seems to be a little confusing, isn't there a way bit more like php?, something like:
{{data}} where data is var data or function,
-data- where data is var data or function,
etc.
PD: im new to node and javascript, but i have experience on php, so any tutorial or book to do so will be appreciated
i recommend using Swig js and it does exactly what you are asking for, just pass the variables from the node server, in express js i use it like this:
res.render('index.html', {'name': 'mecha'});
then in my index.html i would just use:
<p>{{ name }}</p>