Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Return 0 if empty

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
aidendoyle1981
Smarty Rookie


Joined: 11 Jan 2016
Posts: 9

PostPosted: Tue Feb 09, 2016 1:04 pm    Post subject: Return 0 if empty Reply with quote

I am using the following code to display when a user has a message.






Code:
{if $isLogin}


<div style="border:solid 3px; border-color:#008BD1; border-radius: 5px; float:left; height:21px; text-align:center; width:18px; color:#fff; margin-left:10px; margin-top:10px; padding-top:1px; padding-right:1px; position: relative;">
   
      {foreach from=$account_menu item='mItem'}
         {if $mItem.Key == 'my_messages' && !$config.messages_module}{else}
            

               {if $mItem.Key == 'my_messages' && $new_messages}
                  <a style="color:#fff;" title="{$lang.new_message_available|replace:'[count]':$new_messages}" href="{$rlBase}{if $config.mod_rewrite}{$pages.my_messages}.html{else}?page={$pages.my_messages}{/if}">{$new_messages}</a>
                  {/if}
            
         {/if}
      {/foreach}
      
</div>{/if}




How would I get this to return a 0 value if no messages. So if no messages you should see 0.


Thanks
Aiden
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Feb 09, 2016 8:10 pm    Post subject: Reply with quote

1. Move styles to CSS already. You're polluting your code to complete unreadability.
2.
Code:
{if $isLogin}
<div style="border:solid 3px; border-color:#008BD1; border-radius: 5px; float:left; height:21px; text-align:center; width:18px; color:#fff; margin-left:10px; margin-top:10px; padding-top:1px; padding-right:1px; position: relative;">
  {foreach $account_menu as $mItem}
    {if $mItem.Key == 'my_messages' && !$config.messages_module}0{else}
      {if $new_messages}<a style="color:#fff;" title="{$lang.new_message_available|replace:'[count]':$new_messages}" href="{$rlBase}{if $config.mod_rewrite}{$pages.my_messages}.html{else}?page={$pages.my_messages}{/if}">{$new_messages}</a>{else}0{/if}
      {break}
    {/if}
  {/foreach}
</div>
{/if}
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP