Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 940119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:54:09+00:00 2026-05-15T21:54:09+00:00

First-timer here, I hope I explain this well enough… PHP/Smarty, I’m working on a

  • 0

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)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:54:10+00:00Added an answer on May 15, 2026 at 9:54 pm

    While I’m guessing it is possible to do this in Smarty, it does seem that you’re mixing your business logic and presentation logic here. Personally, I’d consider splicing your array in in two parts (general and places) in the PHP calling this template.

    $placesNotes = array();
    $generalNotes = array();
    
    array_filter($notes, function($note) {
        global $placesNotes, $generalNotes;
        if($note->get_place_id() == null) {
            $generalNotes[] = $note;
        } else {
            $placesNotes[$note->get_place_id()][] = $note;
        }
    });
    

    (note: this uses an anonymous function, so >5.3 only – if you want this to run on older versions, move the function to it’s own named function and use the Callback type)

    You then end up with two arrays you easily loop over, using an isset($notes_places.$curr_place_id) within the Places-loop to find out if the place has any notes.

    Also, you forgot the {}’s around the get_text() calls.

    I’ve whipped up a quick sample, to be found at: http://gist.github.com/479392 – hope that helps?

    BTW: Your question was very clear, and explained what you want to do, even detailing the decision behind what you were doing when it wasn’t immediately obvious – so for a first-time: excellent question!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 531k
  • Answers 531k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Let a = (x+1)^2, that's 2 ops. Then y=3a +… May 16, 2026 at 11:49 pm
  • Editorial Team
    Editorial Team added an answer Hmm I got the problem: after a little search on… May 16, 2026 at 11:49 pm
  • Editorial Team
    Editorial Team added an answer Connections have a close method as specified in PEP-249 (Python… May 16, 2026 at 11:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

This is my first time here so I hope I post this question at
this is my first time posting my problem here, i hope i get help
Its my first time asking here, i hope get help, and meanwhile, help you
Just want to start out by saying this seems like a great site, hope
I have read several interesting C#/F# comparisons here on stackoverflow. So, first of all,
I gotta admit that's a first-timer bug for me. I've never seen that... I
here's what I need (it's a bit hard to explain): I have 2 window
I'm trying to explain as best as I can, sorry for my English. I
I'm learning about POSIX threads right now, but I guess this is just a
I've been through the Dojo docs as well as the API and tried Google

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.