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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:37:36+00:00 2026-05-31T00:37:36+00:00

I have the following code in my smarty template: {foreach from=$categories item=l} <tr>———-START—————</tr> <br/>

  • 0

I have the following code in my smarty template:

{foreach from=$categories item=l}
          <tr>----------START---------------</tr> <br/>

        {$l.category_name|strip_tags}
        {$l.sub_category}

        {while $l.sub_category}

            <td>{$l.category_name|strip_tags}</td>
            {foreach from=$l.sub_category item=k}
                <td>{$k.category_name|strip_tags}</td>
                <br/>
            {/foreach}

            <br/>
        {/while}

        ----------END---------------
            <br/>
        <br/>
    {/foreach}

This outputs:

———-START—————
Teachers & StaffArray

———-END—————

———-START—————
PTA & Foundations

———-END—————

———-START—————
Enrichment Programs

———-END—————

Teachers & Staff 5th Grade 6th Grade
PTA & Foundations
Enrichment Programs

I Expected it to print out:

———-START—————
Teachers & Staff

5th Grade 6th Grade

———-END—————

———-START—————
PTA & Foundations

———-END—————

———-START—————
Enrichment Programs

———-END—————

Seems like the output gets printed after the for loop. I’m new to smarty templates and not really understanding why its printing like that.

In addition, I have another question:

{while $l.sub_category}

                {foreach from=$l.sub_category item=k}
                       <br/>
                    { $k.category_name|strip_tags }

                {/foreach}


               { assign var=l value=$l.sub_category}

                <br/>
            {/while}

I want to update the loop condition variable..but I’m not really sure how other then the assign method i did.

Any advice appreciated.

  • 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-31T00:37:37+00:00Added an answer on May 31, 2026 at 12:37 am

    I think the problem may be down to your table structure, you open and close the tr before outputting the td tags and some browsers will then display the content out of order.

    it should be along the lines of

    {foreach cat loop}
      <tr>
        <td>
          {while loop}
        </td>
        <td>
          {foreach loop}
        </td>
      </tr>
    {/close foreach loop}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following smarty code: {foreach from=$additional_fields item=v} {if $v.fieldid eq 5} {php}
I have following code in a file with extension .tpl (Smarty template) {foreach from=$randomSites
I have following code: private void ProcessQueue() { foreach (MessageQueueItem item in GetNextQueuedItem()) PerformAction(item);
I have the following code in django.template: class Template(object): def __init__(self, template_string, origin=None, name='<Unknown
I have the following code on my site (using php and smarty) to try
How do you include Javascript from a CDN source using Smarty? We have code
I am using smarty php template and sql server I have the following tables
I have the following smarty code to display in table.... <table id=hor-zebra summary=DIsh Information>
I have recently found out that Smarty, differently from Django template engine, does not
I have following code in my application: // to set tip - photo in

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.