Smarty foreach how to start at array 1 not 0 - foreach

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}

Related

How do I count the number of occurrence of an item in a list? - Dart

I would like to know how many occurrences of a single item consists in a list in dart. As far as I know, the contains method checks only up to the first occurrence and returns a bool.
Following counts how many "1"s are in list:
[1, 2, 1].where((item) => item == 1).length

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.

How i get value from smarty array

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

How is a #Model count subtracted

How is a #Model count subtracted from another #Model count to display the difference. For example the two counts below. So answer should be 0
`#Model.Where(x=> x.Product != null).Count(x=> x.Product.name)
Subtract
#Model.Count(x=> x.Product.name)`
You need to use the - operator, just like any other C# code.
However, you also need to wrap the entire expression in parentheses to prevent Razor from treating the - as markup:
#(a - b)

Creating a simple array with multiple values in Ruby on Rails

Arrays have always been my downfall in every language I've worked with, but I'm in a situation where I really need to create a dynamic array of multiple items in Rails (note - none of these are related to a model).
Briefly, each element of the array should hold 3 values - a word, it's language, and a translation into English. For example, here's what I'd like to do:
myArray = Array.new
And then I'd like to push some values to the array (note - the actual content is taken from elsewhere - although not a model - and will need to be added via a loop, rather than hard coded as it is here):
myArray[0] = [["bonjour"], ["French"], ["hello"]]
myArray[1] = [["goddag"], ["Danish"], ["good day"]]
myArray[2] = [["Stuhl"], ["German"], ["chair"]]
I would like to create a loop to list each of the items on a single line, something like this:
<ul>
<li>bonjour is French for hello</li>
<li>goddag is Danish for good day</li>
<li>Stuhl is German for chair</li>
</ul>
However, I'm struggling to (a) work out how to push multiple values to a single array element and (b) how I would loop through and display the results.
Unfortunately, I'm not getting very far at all. I can't seem to work out how to push multiple values to a single array element (what normally happens is that the [] brackets get included in the output, which I obviously don't want - so it's possibly a notation error).
Should I be using a hash instead?
At the moment, I have three separate arrays, which is what I've always done, but I don't particularly like - that is, one array to hold the original word, one array to hold the language, and a final array to hold the translation. While it works, I'm sure this is a better approach - if I could work it out!
Thanks!
Ok, let's say you have the words you'd like in a CSV file:
# words.csv
bonjour,French,hello
goddag,Danish,good day
stuhl,German,chair
Now in our program we can do the following:
words = []
File.open('words.csv').each do |line|
# chomp removes the newline at the end of the line
# split(',') will split the line on commas and return an array of the values
# We then push the array of values onto our words array
words.push(line.chomp.split(','))
end
After this code is executed, the words array had three items in it, each item is an array that is based off of our file.
words[0] # => ["bonjour", "French", "hello"]
words[1] # => ["goddag", "Danish", "good day"]
words[2] # => ["stuhl", "German", "chair"]
Now we want to display these items.
puts "<ul>"
words.each do |word|
# word is an array, word[0], word[1] and word[2] are available
puts "<li>#{word[0]} is #{word[1]} for #{word[2]}</li>"
end
puts "</ul>"
This gives the following output:
<ul>
<li>bonjour is French for hello</li>
<li>goddag is Danish for good day</li>
<li>stuhl is German for chair</li>
</ul>
Also, you didn't ask about it, but you can access part of a given array by using the following:
words[0][1] # => "French"
This is telling ruby that you want to look at the first (Ruby arrays are zero based) element of the words array. Ruby finds that element (["bonjour", "French", "hello"]) and sees that it's also an array. You then asked for the second item ([1]) of that array and Ruby returns the string "French".
You mean something like this?
myArray.map{|s|"<li>#{[s[0],'is',s[1],'for',s[2]].join(" ")}</li>"}
Thanks for your help guys! I managed to figure a solution out based on your advice
For the benefit of anyone else who stumbles across this problem, here's my elided code. NB: I use three variables called text, language and translation, but I suppose you could replace these with a single array with three separate elements, as Jason suggests above.
In the Controller (content is being added via a loop):
#loop start
my_array.push(["#{text}", "#{language}", "#{translation}"])
#loop end
In the View:
<ul>
<% my_array.each do |item| %>
<li><%= item[0] # 0 is the original text %> is
<%= item[1] # 1 is the language %> for
<%= item[2] # 2 is the translation %></li>
<% end %>
</ul>
Thanks again!

Resources