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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:41:28+00:00 2026-05-16T17:41:28+00:00

I am having trouble getting the below array to display properly in a smarty

  • 0

I am having trouble getting the below array to display properly in a smarty template file. If anyone can help point me in the right direction I would be most thankful.

my template code looks like this:

          {foreach from=$trackingGroups item=gender key=k item=v}
          {assign var=tc value="`$v.id`"}    
          {$v.title} ({$v.productCount})<br />

{foreach item=department from=$trackingGroups.$tc item=v2}
{$v2.title}
{/foreach}
{/foreach}

but the page displays like this:

          Women (3)<br />
           W<br />
                    7<br />
                    3<br />
                    Footwear<br />
                    Accessories<br />

          Men (2)<br />
           M<br />
                    7<br />
                    2<br />
                    Footwear<br />




Array

(
[71] => Array
(
[title] => Women
[id] => 71
[productCount] => 3
[171] => Array
(
[id] => 171
[title] => Footwear
[productCount] => 2
[74] => Array
(
[id] => 74
[title] => Boots
[productCount] => 2
)

            )

        [172] => Array
            (
                [id] => 172
                [title] => Accessories
                [productCount] => 1
                [74] => Array
                    (
                        [id] => 74
                        [title] => Boots
                        [productCount] => 1
                    )

            )

    )

[72] => Array
    (
        [title] => Men
        [id] => 72
        [productCount] => 2
        [171] => Array
            (
                [id] => 171
                [title] => Footwear
                [productCount] => 2
                [74] => Array
                    (
                        [id] => 74
                        [title] => Boots
                        [productCount] => 2
                    )

            )

    )

)

  • 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-16T17:41:28+00:00Added an answer on May 16, 2026 at 5:41 pm

    When you are looping in your second foreach you are looping through all the elements, not just the title keys. For example:

    {foreach item=department from=$trackingGroups.72 item=v2} 
       {$v2.title}
    {/foreach}
    

    in this case $v2 will take the following values:

    [title] => Men
    [id] => 72 
    [productCount] => 2 
    [171] => Array 
     ( 
                    [id] => 171 
                    [title] => Footwear 
                    [productCount] => 2 
                    [74] => Array 
                        ( 
                            [id] => 74 
                            [title] => Boots 
                            [productCount] => 2 
                        ) 
    
     ) 
    

    The first, second and third value will be only a string. Since it is not an array, $v2.title will return the “title”‘th element (the first one), returning the first character: M,7,2
    The fourth element is an array with the “title” key, and it is returned correctly: Footwear.

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

Sidebar

Related Questions

I'm having trouble getting a rotary encoder to work properly with AVR micro controllers.
I'm having trouble getting the right number of elements in the ArrayList alt in
I am having trouble getting the compiler to accept my below defined user data
I'm having trouble getting the very last draggable item in the loop below to
I have a table as below, I'm having trouble getting the results I want.
I've been having trouble getting my ASP.NET application to automatically log users into the
I'm having trouble getting the following to work in SQL Server 2k, but it
I am having trouble getting my ASP.NET application to start an application. For example
I'm having trouble getting a rails app on Dreamhost's Passenger to see compiled libraries
I'm having trouble getting in touch with SQL Server Managemen Studio 2008! I want

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.