How can you get a dynamically named variable in handlebars? - handlebars.js

I am trying to output a table using handlebars.
Right now it loops through the each row, and then through each column, but how can I grab the data from the row based on {{col.name}}?
See here, I need to get COLUMNNAME from {{col.name}}
{{#rows as |row|}}
<tr>
{{#../cols as |col|}}
<td>{{row.COLUMNNAME}}</td>
{{/../cols}}
</tr>
{{/rows}}
In js this would be like row[index][col.name];
Any idea for solutions?

Found the answer, it's the lookup tag.
{{lookup row col.name}}
is equal to
row[col.name]

Related

Checking for a table row using DomCrawler

I am writing a phpunit test... on my page I have several rows, one of them is like this:
<tr><td>MATCH<small><span class="glyphicon glyphicon-pushpin"></span></small></td></tr>
Some are like this:
<tr><td>NOT A MATCH 1</td></tr>
<tr><td>NOT A MATCH 2</td></tr>
<tr><td>NOT A MATCH 3</td></tr>
how can I run a test to check that the row with the pushpin glyphicon is the one with "MATCH"?
Basically I want the test to confirm that the glyphicon is appearing on the correct row, and just having something like $crawler->filter('small:contains("' . $glyphCode . '")')->count() only confirms that the glyph exists - not that it's in the right place.
Any help appreciated, thank you.
You can use XPath Selectors with Symfony's DomCrawler.
To select your desired element use this XPath expression:
//td//small/span[#class="glyphicon glyphicon-pushpin"]
Then place it inside a PHPUnit assertion.
$this->assertEquals(1,
$crawler->filterXPath('//td//small/span[#class="glyphicon glyphicon-pushpin"]')->count()
);
I've used assertEquals 1 as expected value, to ensure that one element is found on the page.
Actually, the question can be treated as a string match problem.
There are several different ways to do that.
use PHP Simple HTML DOM Parser
$ret = $html->find('td[class=*glyph]');
use regular expression in PHP
the pattern string may like /class="[^"]+glyph/
run grep command in the shell
$ grep glyph xxx.php

AngularJS Multiple class using expression

I have a table where I need to apply two different classes, using expressions.
1st class is applied based on following expression.
{'Up':'class-up', 'Down':'class-down'}[a.status]
and 2nd class is applied based on bold: !a.read
The classes here are class-up, class-down, bold.
So how should be the expression framed? I tried:
<tr ng-repeat="a in all" ng-class="{{'Up':'class-up', 'Down':'class-down'}[a.status],bold: !a.read}">
<tr ng-repeat="a in all" ng-class="{'Up':'class-up', 'Down':'class-down'}[a.status],bold: !a.read">
But I keep getting errors in console. What is the correct format to apply these classes based on the given expressions
With the clarification from your comment:
<tr ng-repeat="a in all" ng-class="{'class-up': a.status=='up', 'class-down': a.status=='down', 'bold': !a.read}">hello world</tr>

How to select all cells <th> and <td> alike

Pardon if this is very basic. I have been trying to traverse each cell including header cells in an array of rows. Is there an OR operator I can use in the Nokogiri CSS selector?
thang= Nokogiri::HTML(IO.read "|cat page.html").css('table[#id="costbasisTable"] tr')
Correctly fetches all rows including a header row (which repeats on subsequent pages):
thang[0].inner_html
=> <th class="tLeft"></th><th>cellA2</th><th>cellA3data</th>
thang[1].inner_html
=> <td>cellB1</td><td>cellB2</td><td>cellB3data</td>
The trouble is with the following, which may return blank if that row contains only th's not td's:
N=0
thang[N].css("td").map{|c| c.text.strip.gsub(/\t.*/,"").delete ",".tr("&/|:;\n","_")}.to_a
What parameter to .css(...) will mean "match any <td> OR <th> cell"?
Is this possible/better done with .xpath() instead for these Nokogiri XML Elements?
You want to use either of the following:
# thang[n] is a Nokogiri <tr> node
cells = thang[n].css('th,td')
cells = thang[n].xpath('./th | ./td')
Note that the CSS version will match any embedded tables (if you had such a horror) while the XPath version will only match direct children of the row.

Tal condition always evaluates to false

I'm using plone and trying to display a form result in a page template.
I'm trying to filter some database results using tal:condition with a python expression but it always evaluates to false.
The code looks like this:
<tr tal:repeat="result view/results">
<td> <span tal:condition="python:view.teams[0]==result.team_id" tal:replace="result/position">Position</span></td>
<td> <span tal:condition="python:view.teams[1]==result.team_id" tal:replace="result/position">Position</span></td>
</tr>
I want the table cells to be filled with the team position when the team id is matched in the result, but the cells always are empty.
If I remove the tal:condition from the span and replace the tal:replace="result/position" with tal:replace=python:view.teams[0]==result.team_id it prints True or False so I can check that the result is correct.
Can anyone help me about this issue? Why does tal:condition allways evaluate false?
I'd fully expect this to work, so something else must be wrong.
Python expressions such as yours are commonplace; there are several examples on the internet to show they do normally work.
Try further debugging the values with tal:replace="python:repr(view.teams)" and tal:replace="python:repr(result.team_id)" statements and similar to be 100% certain of what your data structures look like.

Finding First Row in a RDLC Table

I have a table in a RDLC report which is utilized as a subreport, and the first column of this table is a static string. Does anyone know how I can determine if a row is the first in the table. I tried using "=First("My String")" but it didn't work.
Looking at the link supplied by ThatBloke in his answer, I found the RowNumber command.
Which means that this worked:
=IIf(RowNumber(Nothing)=1,"myString", "")
Aggregate functions work with "Scope', referring to the paragraph scope in this MSDN article, might help...
http://msdn.microsoft.com/fr-fr/library/ms252112(VS.80).aspx"
From what I understand you may have to define a scope or try =First("MyString", Nothing).
=IIF((RowNumber(Nothing) Mod <>)=0)
<> Indicate No of Rows Which you want To Display

Resources