How i get value from smarty array - foreach

This is my variable in array in smarty file
{$CountKey}
The output of this is "Array".
I want to get all value from it in smarty file.

You need to use a foreach loop to get the values out of an array.
{foreach $CountKey as $row}
<p>{$row.name}</p>
{/foreach}
This is very basic knowledge. Please brush up your knowledge on PHP and Smarty.
Smarty Foreach Documentation

Related

How to filter out empty arrays/lists in OData v4 Query?

In OData V4, you are able to filter out empty strings as follows:
OData/v4/2.0/Case?filter=Date ne null
or OData/v4/2.0/Case?filter=Date ne ''
I, however, have an OData query which requires filtering out an empty array/list of names (empty would be: [] so an empty list). Lists cannot be filtered out in the same way:
OData/v4/2.0/Case?filter=Names ne null
does not work. Same goes for the other method.
Is there another way to filter out lists like this Names one?
Thanks in advance
...Or you can use any() operator.
The any operator without an argument returns true if the collection is not empty.
docs
OData/v4/2.0/Case?$filter=Names/any()
If your service supports this operation, you can use the $it literal:
OData/v4/2.0/Case?filter=$it/Names/$count gt 0
The below one was working for me, hope this helps.
https://api-uk.securitycenter.windows.com/api/machines?$filter=not machineTags/any()
Am filtering out the results where the machine tags are empty array.

beam.io.WriteToText add new line after each value - can it be removed?

My pipeline looks similar to the following:
parDo return list per processed line | beam.io.WriteToText
beam.io.WriteToText adds a new line after each list element. How can I remove this new line and have the values separated by comma so I will be able to build CSV file
Any help is very appreciated!
Thanks,
eilalan
To remove the newline char, you can use this:
beam.io.WriteToText(append_trailing_newlines=False)
But for adding commas between your values, there's no out-of-the-box feature on TextIO to convert to CSV. But, you can check this answer for a user defined PTransform that can be applied to your PCollection in order to convert dictionary data into csv data.

How to itearate foreach loop in smarty as key maps to val in php

I am trying to use foreach loop in smarty after assigning an associative array with unordered keys but it is not working. I need both the keys and the values. How do I do this.
The assigned array :
$arr[34] = 'Profile';
$arr[70] = 'Logo';
$arr[300] = 'Items';
$this->assign('arr', $arr);
Have a look at foreach.
Example, adjusted to your array:
<ul>
{foreach $arr as $keyvar=>$itemvar}
<li>Key {$keyvar} : {$itemvar} </li>
{/foreach}
</ul>
The Smarty manual has some more examples to help you further if needed.

Smarty foreach how to start at array 1 not 0

i have like a 2 foreach loops, first one with a image. So thats only the first item. But in me second foreach i wanted to start showing the result at array 1. Not 0 then i have like 2 times the second post.
First foreach
{foreach $cm->find('title,url,auteur,datum,reacties,topics,afbeelding,tekst', 'Blog') as $item}
{if $item#first}
{/if}
{/foreach}
Second for each
{foreach $cm->find('title,url,auteur,datum,reacties,topics,tekst', 'Blog') as $item}
{/foeach}
What do i need to add in me second foreach to start showing my results started by array 1.
Sorry if this a noob question, im not really good at smarty.
You can skip the first item in the second foreach with {continue}:
{foreach $cm->find('title,url,auteur,datum,reacties,topics,afbeelding,tekst', 'Blog') as $item}
{if $item#first}
{continue}
{/if}
... code for the other items here ...
{/foreach}

Formatting results from SQL in Ruby On Rails

I have a custom SQL query that I run with this line:
#avg_score = "#{ActiveRecord::Base.connection.execute(#avg_score_SQL)}"
when that is run, #avg_score has a value of:
[{"score"=>8, 0=>8}]
the results are correct, but it prints it like that :-/ I just want it to print out the "8"
How do I get it to just print the value of score?
[{"score"=>8, 0=>8}] is just an array with one element, and that element is a hash. So you can access the score like this:
#avg_score[0]['score']
if you use execute method, you have to free the Result object after you're done using it.
Also your statement can be used without quotes.
if you always have 1 result row, you should better use selecy_one
#avg_score = ActiveRecord::Base.connection.select_one(#avg_score_SQL)['score']

Resources