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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:45:20+00:00 2026-06-13T03:45:20+00:00

My scenario: <table> <thead> <tr> <th>Name</th> <th>Email</th> </tr> </thead> <tbody> {foreach from=$users item=user} <tr>

  • 0

My scenario:

<table>
    <thead>
        <tr>
            <th>Name</th>
            <th>Email</th>
        </tr>
    </thead>
    <tbody>
        {foreach from=$users item=user}
            <tr>
                <td>{$user.name}</td>
                <td>{$user.email}</td>
            </tr>
        {foreachelse}
            There are no users....
        {/foreach}
    </tbody>
</table>

Now when there are no users I have an ugly table, so I’ll add:

{if $users|count > 0}
    <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Email</th>
            </tr>
        </thead>
        <tbody>
            {foreach from=$users item=user}
                <tr>
                    <td>{$user.name}</td>
                    <td>{$user.email}</td>
                </tr>
            {foreachelse}
                There are no users....
            {/foreach}
        </tbody>
    </table>
{else}
    There are no users....
{/if}

But now my {foreachelse} is useless.

So I delete the {foreachelse} There are no users.... part and conclude that {foreachelse} is useless.

This problem I have in <table>, <ol>, <ul> etc..

Does anyone have a solution so I’m able to use {foreachelse}?

Thanks!

  • 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-13T03:45:21+00:00Added an answer on June 13, 2026 at 3:45 am

    You can have one row which says there are no users, eg:

    <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Email</th>
            </tr>
        </thead>
        <tbody>
            {foreach from=$users item=user}
                <tr>
                    <td>{$user.name}</td>
                    <td>{$user.email}</td>
                </tr>
            {foreachelse}
                <tr>
                    <td colspan="2">There are no users....</td>
                </tr>
            {/foreach}
        </tbody>
    </table>
    

    But I can understand it when this is not the desired result.

    Sometimes you might use divs in a foreach instead of table or lists contents. Check the smarty documentation on this:
    http://www.smarty.net/docs/en/language.function.foreach.tpl

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

Sidebar

Related Questions

Here's a scenario: There are users, users have skills. If a user specifies new
Simple scenario: table view controller, with 5.000 rows. I have 5000 images name from
I have the scenario where the data from a single table must be in
I have the following HTML: <table> <thead> <tr> <th>Id</th> <th>Name</th> <th>Description</th> <th>Actions</th> </tr> </thead>
I have the following scenario: User X logs in to the application from location
I have a scenario like <table> <thead> <tr> <th id =myid1>header1</th> <th id =myid2>headre
I have a very basic one table scenario; tblFamiles entryID : Int name: Text
I have the following scenario: Database A.table A.name Database A.table A.Application Database B.table B.name
I have a scenario outline table that looks like the following: Scenario Outline: Verify
I have the following scenario: a table of projects and a table of persons,

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.