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 8391437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:15:40+00:00 2026-06-09T19:15:40+00:00

So I pass a PHP stdClass() object to Smarty, which looks like this, for

  • 0

So I pass a PHP stdClass() object to Smarty, which looks like this, for example :

stdClass Object
(
    [1] => stdClass Object
        (
            [id] => 1
            [children] => stdClass Object
                (
                    [4123] => stdClass Object
                        (
                            [id] => 4123
                            [children] => stdClass Object
                                (
                                    [221] => stdClass Object
                                        (
                                            [id] => 221
                                            [children] => stdClass Object
                                                (
                                                )
                                        ),
                                    [55] => stdClass Object
                                        (
                                            [id] => 55
                                            [children] => stdClass Object
                                                (
                                                )
                                        )
                                )
                        ),
                    [666] => stdClass Object
                        (
                             [id] => 666
                             [children] => stdClass Object
                                 (
                                 )
                        )
                )
        )
)

Each object has an id and children, which have the same structure.
How can I output all the id-s recursively like the this: 1, 4123, 221, 55, 666 using Smarty ?

  • 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-06-09T19:15:42+00:00Added an answer on June 9, 2026 at 7:15 pm

    There are two options for recursive data handling. The preferred solutions is using {function}. Something along the lines of:

    {function name=printId comma=false data=false}
      {if $comma}, {/if}{$object->id}
      {foreach $data.children as $object}
        {printId data=$object comma=true}
      {/foreach}
    {/function}
    
    {* invoke with: *}
    {printId data=$yourObjectStructure}
    

    The other – Smarty2 compatible – option is using {include}:

    {* recursive-thing.tpl *}
    {if $comma}, {/if}{$object->id}
    {foreach from=$data.children item="object"}
      {include file="recursive-thing.tpl" data=$object comma=true}
    {/foreach}
    
    {* invoke with: *}
    {include file="recursive-thing.tpl" data=$yourObjectStructure}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form like this : <form method=post name=change_pass id=change_pass action=change_pass2.php> <input
I'm trying to pass this to a PHP script through AJAX: var answers={}; for
Why this parameter does not pass: file.php?t=%26quot%3B%26gt%3B%0A%09%09%09%26lt Instead it gives: Forbidden You don't have
I create a custom application, and I like to pass some PHP variables into
I was wondering what the best way would be to pass a php object
This is an extension question of PHP pass in $this to function outside class
how do i pass php array's to ruby script as an argument so that
The regular expression ^/wp-[^./]+\.php$ matches: wp-config.php wp-commentsrss2.php wp-pass.php wp-rdf.php [...] But I need another
Possible Duplicate: Pass a PHP string to a Javascript variable (including escaping newlines) Hy,
I am trying to pass a php variable into a java script window.location that

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.