|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
draxander Smarty n00b
Joined: 12 May 2016 Posts: 3
|
Posted: Thu May 12, 2016 10:43 am Post subject: Comparing & changing array items in a foreach / section |
|
|
Hello,
I couldn't find a solution for my problem, so I hope you can help me. I'm a beginner with Smarty / PHP. Thats my array:
Code: | [player_items] => Array (
[0] => Array (
[ITEM_NAME] => Player - Item1 - Yellow
[ITEM_ID] => 1
[ITEM_IMAGE] => images/item1_yellow.jpg
[ITEM_LINK] => http://www...
[ITEM_NUMBER] => 24
)
[1] => Array (
[ITEM_NAME] => Player - Item1 - Orange
[ITEM_ID] => 2
[ITEM_IMAGE] => images/item1_orange.jpg
[ITEM_LINK] => http://www...
[ITEM_NUMBER] => 24
)
[2] => Array (
[ITEM_NAME] => Player - Item2 - Red
[ITEM_ID] => 3
[ITEM_IMAGE] => images/item2_red.jpg
[ITEM_LINK] => http://www...
[ITEM_NUMBER] => 10
)
...
) |
Currently I got a very long list with a regular foreach loop:
Code: | <a href="http://www.../item1_yellow.html">
Player - Item1 - Yellow<br/>
Number: 24<br/>
<img src="images/item1_yellow.jpg"><br/>
</a>
<a href="http://www.../item1_orange.html">
Player - Item1 - Orange<br/>
Number: 24<br/>
<img src="images/item1_orange.jpg"><br/>
</a>
<a href="http://www.../item2_red.html">
Player - Item2 - Red<br/>
Number: 10<br/>
<img src="images/item2_red.jpg"><br/>
</a>
...
|
But I wan't to shorten (merge) this list to the following example when the first two parts of the "[ITEM_NAME]" are the same and [ITEM_NUMBER] too. If not, then it should be displayed like before. For the result I don't need the first part of "[ITEM_NAME]", only the second and third, but seperated:
Code: | Item1<br/>
<a href="http://www.../item1_yellow.html">Yellow</a>
<a href="http://www.../item1_orange.html">Orange</a><br/>
Number: 24<br/>
<img src="images/item1_yellow.jpg"><br/>
Colors: Yellow, Orange
<a href="http://www.../item2_red.html">
Player - Item2 - Red<br/>
Number: 10<br/>
<img src="images/item2_red.jpg"><br/>
Colors: Red
</a>
...
|
Any ideas how to solve this??? Please help me!
(PS: I can't change anything to the original array structur itself.)[/code] |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu May 12, 2016 10:37 pm Post subject: |
|
|
Your solution is to not do that at all.
Smarty is not a programming language, why do you CHANGE anything in it?… |
|
Back to top |
|
draxander Smarty n00b
Joined: 12 May 2016 Posts: 3
|
Posted: Fri May 13, 2016 6:40 am Post subject: |
|
|
Hello,
as far as I know is it possible - in this thread the user has figured it out for his self with section. Sadly he didn't write how he did it exactly.
http://www.smarty.net/forums/viewtopic.php?p=90408#90408
Of course in my case there are 2-3 additional things, but they should be possible too (split an item to three vars).
Anyone with a solution for my problem? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri May 13, 2016 9:10 am Post subject: |
|
|
draxander wrote: | as far as I know is it possible |
It is possible to drink molten iron. Only once, though…
But possible, nonetheless. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|