First-timer here, I hope I explain this well enough...
PHP/Smarty, I'm working on a section of a page that displays bullet lists of notes associated with either the general page, or individual places on that page. Some places don't have notes. Something like:
General
- note 1
New York
- note 2
- note 3
Boston
- note 4
I have two arrays assigned to the .tpl I'm working with and populated by the UI class: $places and $notes
$places contains place objects, each unique by place_id
$notes contains uniquely identified note objects, each of which may or may not have a place_id as one of the attributes
here's what i'm thinking:
{if (**ANY NOTES EXIST IN $notes WITH NO place_id**)}
<ul id="list-general">
<h4>General</h4>
{foreach from=**[NOTES WITH NO place_id]** item=note}
<li id="note-{$note->get_id()}">$note->get_text()</li>
{/foreach}
</ul>
{else}
<ul id="list-general" class="hide">
<h4>General</h4>
</ul>
{/if}
{foreach from=$places item=place}
{assign var=curr_place_id value=$place->get_id()}
{if (**ANY NOTES EXIST IN $notes WHERE place_id == $curr_place_id**)}
<ul id="list-{$curr_place_id}">
<h4>{$place->get_name()}</h4>
{foreach from=**[NOTES WHERE place_id == $curr_place_id]** item=note}
<li id="note-{$note->get_id()}">$note->get_text()</li>
{/foreach}
</ul>
{else}
<ul id="list-{$curr_place_id}" class="hide">
<h4>{$place->get_name()}</h4>
</ul>
{/if}
{/foreach}
I'm pretty new to all of this, and I'm having a hard time with the items in CAPS...so, my question is: what's the best way to evaluate the attributes of the objects in the two different arrays, and possibly build temp arrays that contain only the notes that i need.
(In case you're wondering, I'm creating the hidden nodes so I can access them via javascript and don't have to worry about order)