Concatenation string with variable in emblem.js - ember.js

I need in Emblem.js to transmit to i18n helper concatenated string constant with variable value, How can i do it?
each item in model.items
div
t "dict.{{item}}"
returns error
Missing translation for key "dict.{{item}}"

If you're using Handlebars 1.3+, you can use a subexpression. First, write a string concatenation helper:
Ember.Handlebars.helper('concat', function (a, b) {
return a + b;
});
Then use it like this (sorry, I don't know Emblem so I'm going to use the normal stache syntax):
{{t (concat 'dict.' item)}}

Related

How do I get the last element of a slice in a golang template

I can get the size of a slice in a template like this
{{$size := len .Things}}
And I can index a slice in a template like this:
{{index .Things 4}}
But
{{index .Things $size}}
gives an "out of range" error because indexing a slice is zero-based.
Do I have do all the function defining things or is there arithmetic available I can use?
I.e. how do I do this https://stackoverflow.com/a/22535888 but in a golang template.
Defining a minus function: https://stackoverflow.com/a/24838050/10245
There is no arithmetic available by default, but you can add this functionality using a FuncMap.
Here's how to add an "add" function that covers this case and other scenarios:
t := template.Must(template.New("").Funcs(template.FuncMap{
"add": func(a, b int) int { return a + b },
}).Parse(theTemplate)
Use it in the template like this:
{{index .Things (add $size -1)}}
In go templates could be viewed as more "passive" than in other languages or some frameworks. The idea of passive views is that they do not include much logic but get passed all their data in.
So you could pass "LastThing" to your template, which has the last Thing assigned.
This does not answer your question directly but this is just an alternative you could consider.
Define variables out of the loop (range):
{{$i:=""}}
{{$el:=""}}
{{range $i,$el = $.Sorteados}}{{end}}
<span >{{$i}} - {{$el}} </span>
So,use them after the loop.

Equivalent of a predicate's ANY for Swift 3 filter expression

When using a predicate, we can have:
filterPredicate = [NSPredicate predicateWithFormat:#"(ANY names.firstName contains[c] %#), nameToSearchFor];
This use of ANY allows us to find any object where any of the objects in the names collection has a firstName containing the desired text.
Is it possible to do something similar with filter expressions in Swift 3? In other words, something like:
allPeople.filter { $0.(ANY)names.firstName.contains(searchString) };
(The above ANY syntax is made up for illustration).
Perhaps could be done by nesting a reduce that concatenates all the firstNames, then see if my target string is contained in that?
allPeople.filter { $0.names.contains(where: { $0.firstName.contains(searchString) }) }

How to render multiple templates using #each in a handlebars?

I have one array of objects inside this objects I have some list of id's and using this id's I have to render multiple templates using #each loop for handlebars.
Simple this statement will return me the list of containing names of template.
{{#each data in sections1}}
{{data.id}}
{{/each}}
Output :
A B C D E F G H I J K L M N O P Q R S T U V W X
Consider this all A to Z are different template names respectively
Now I'm trying to render all these templates using #each loop in handlebar But I don't know the exact syntax.
For example can we do like this way ?
{{#each data in sections1}}
{{render data.id}} //Here I'm getting error Because of it is not exact syntax
{{/each}}
Maybe you should consider using partials, naming them with the proper name based on data.id value. Then use them like: {{partial data.id}}
DEMO

meteor template compare/passing a variable

I want to do what should be a simple compare but I have been stuck for the longest time on this:
I have a template that calls a list template, each list is a new column.
For the first column, I do NOT want certain fields displayed. Each column has a variable {{type}}
I want to do either:
a) pass type to the list template so that list can render based on type equals something
or
b) do an compare on type before I call list (in an 'each' loop) - e.g.
{{#if $eq myVar "test"}}
Show this text
{{/if}}
Neither approach works.
This seems to be the simplest thing but I am scratching head and unable to find examples.
thank you
Max
Unsure if this does what you want to achieve, it would help if you post some of your HTML. But to do what you want in b) couldn't you do:
{{#if isEqual myVar "test"}}
...
{{/if}}
and
Template.example.helpers({
isEqual: function(var1, var2) {
return var1 === var2;
}
});
It is probably easier to use collection.find({type: someType}) to just give your template what it should show. Make someType a session variable and you are done.
This sort example shows this pattern.

grails controller: access to parameter that has a list of elements

I need to access to items stored in a parameter that represents selected elements in a multiselect. I pass selected items from gsp to controller with the following code into the remoteFunction:
params: '\'receiptItemsSelected=\' + jQuery(this).val()'
Now, following the code found in discussion here, I use the closure to get each value, but if I perform a multiselect, the size of receiptItemsSelected is always 1, but value is, for example, 1,2. To get values as a list I've done the following in the controller
params.list("receiptItemsSelected")
but it does not give me two elements if I select two items in the multiselect, but always one element.
The question is: if I select two elements, how can I get each element and use it in the controller? And how can I have that elemnts as Long and not as String?
Thanks
If you're parameters are being passed with string representation of a list, e.g.:
http://yoursite.com/?receiptItemsSelected=1,2,3
You have to split the value using normal Groovy string manipulation and perform the type conversion yourself:
def receiptsAsLongs = params.receiptItemsSelected.split(',')*.toLong()
If your parameters are passed with the convention of repeated parameters makes a list, e.g.:
http://yoursite.com/?receiptItemsSelected=1&receiptItemsSelected=2
Then grails can convert this to a list for you using params.list(), but you must do the final String to Long conversion:
def receiptsAsLongs = params.list('receiptItemsSelected')*.toLong()
params.list() is intended for multi-valued parameters, i.e. it will work if you have
receiptItemsSelected=1&receiptItemsSelected=2
You may have more luck using serialize() rather than val() to build the request body.