When using blaze and handlebars, I can loop through an array of objects as follow:
{{#each cars}}
<p>{{color}}, {{brand}}</p>
{{/each}}
How can I do this with jade?
You have some choices:
each cars
p #{color}, #{brand}
or
each cars
p {{color}}, {{brand}}
or
each cars
p
| You can also do this:
| #{color}, {{brand}}
Related
I'm new to Powershell and I'm putting together a script that will populate all variables from data stored in a Excel file. Basically to create numerous VMs.
This works fine apart from where i have a variable with multiple name/value pairs which powershell needs to be a hashtable.
As each VM will need multiple tags applying, i have a column in excel called Tags.
The data in the field would look something like: "Top = Red `n Bottom = Blue".
I'm struggling to use ConvertFrom-StringData to create the hashtable however for these tags.
If i run:
ConvertFrom-StringData $exceldata.Tags
I end up with something like:
Name Value
---- -----
Top Red `n bottom = blue
I need help please with formatting the excel field correctly so ConvertFrom-StringData properly creates the hashtable. Or a better way of achieving this.
Thanks.
Sorted it, formatted the excel field as: Dept=it;env=prod;owner=Me
Then ran the following commands. No ConvertFrom-StringData required.
$artifacts = Import-Excel -Path "C:\temp\Artifacts.xlsx" -WorkSheetname "VM"
foreach ($artifact in $artifacts) {
$inputkeyvalues = $artifact.Tags
# Create hashtable
$tags = #{}
# Split input string into pairs
$inputkeyvalues.Split(';') |ForEach-Object {
# Split each pair into key and value
$key,$value = $_.Split('=')
# Populate $tags
$tags[$key] = $value
}
}
I have a firebase element that is pulling in the last 5 items
<firebase-element id="base" location="https://mydb.firebaseio.com/mydata" data="{{items}}" keys="{{keys}}" limit="5" ></firebase-element>
That is bound to this repeat region
<template repeat="{{id in keys}}">
<x-chat-list id="chatList" username="{{items[id]['uuid']}}" text="{{items[id]['text']}}" ></x-chat-list>
</template>
I simply need to reverse the order of the repeat region.
I think you just need to observe the array and reverse it (or store the reversed values in another attribute)
Ex :
keysChanged : function() { this.keys.reverse(); }
If the firebase-element sometimes changed the values in the array without triggering the keysChanged function, you can also use the observe object
Just add a custom Polymer expression, e.g.:
PolymerExpressions.prototype.revArray = function(a) {
return a.reverse();
}
and pipe your data to it:
<template repeat="{{id in keys | revArray}}">
Now you can use this anywhere since the expression handler is global.
I want to declare and initialize integer variable in Decision Table. I created a sample rule in .drl file. It's working fine but i want that rule in drool spreadsheet. Anybody know How to do it?
Sample Rule code.
rule "GoodBye1"
salience 5
when
a : Message(count == 45)
then
System.out.println("-----------------");
int temp = a.getTemplatesFromDba("123");
System.out.println("-Raj--> "+temp);
a.setPriority(temp);
update(a);
end
You'll have to write it in to the Action part of your decision table. Here's one way to do it with a decision table. What suites best for your needs requires a bit more info on the details.
Condition | Action
a : Message |
$param | a.setPrio( a.getTemplate( $param) ); update(a);
--------------------------
count == 45 | "123"
If you need, you can add the System.out.prinln calls in the Action block as well. If you have a lot of operations to execute, it might be better to create a helper function for that.
Let's say I have some JSON like this:
{
'my_items': [{'property': '1'}, {'property': '2'}, {'property': '3'}],
'other_items': [{'other_property': 'a'}, {'other_property': 'b'}, {'other_property': 'c'}]
}
I want to iterate through the my_items first, then in each iteration of my_items, I want to iterate through other_items.
I thought it could be done like this:
{{#my_items}}
<div>{{property}}</div>
{{#../other_items}}
<div>{{other_property}}</div>
{{/../other_items}}
{{/my_items}}
But this doesn't work.
Oops, the variable I was passing to the template didn't have all the data I wanted.
I want to add up numbers, that come out of an array in smarty.
The following code shows the total price of every different product in a shoppingcart.
{foreach name=aussen item=data from=$cart_data}
{$data.products_final_price.plain}
{/foreach}
Is there a way to add up all of the single numbers?
I thought of something like giving every {$data.products_final_price.plain} variable a different name, depending on the amount of loops the foreach went through. For example: number1 number2 number3 and than adding them up with smarty math equation.
I figured out how to use the counter but not how to give my Variable a different name each time it loops.
That sounds confusing...
Thank you very much in advance
Smarty3:
{$foo = 0}
{foreach name=aussen item=data from=$cart_data}
{$foo = $foo + $data.products_final_price.plain}
{/foreach}
Smarty 2:
{assign var="foo" value=0}
{foreach name=aussen item=data from=$cart_data}
{assign var"foo" value=$foo+$data.products_final_price.plain}
{/foreach}
If you're stuck with Smarty2, consider using {math} for more complex equations