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

Spaces

 
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 -> Bugs
View previous topic :: View next topic  
Author Message
Margodth
Smarty Rookie


Joined: 28 Mar 2004
Posts: 11

PostPosted: Sun Mar 28, 2004 2:57 am    Post subject: Spaces Reply with quote

I'm new using smarty so I don't know if this is a bug or just a config of my smarty.
I made a tpl file and It works fine but when I see the html code that has been created, I see that there are a lot of white spaces.
ie.

Code:

<tr>
   <th>{$strcolusrrol}</th>
   <td>
      <select name="nivelseguridadid" class="bginput" size="1">
         {foreach item=row from=$niveles}
            {foreach key=key item=nivel from=$row}
               {if $key == 'nivelseguridadid'}
                  <option value="{$nivel}" {if $nivel == $usuario.0.nivelseguridadid}selected{/if} >
               {/if}
               {if $key == 'descripcion'}
                  {$nivel}</option>
               {/if}
            {/foreach}
         {/foreach}
      </select>
   </td>
</tr>


when I see the result of this code, option values are written on column 150 more or less and a lot of spaces are written.
It's this a bug or am I using it bad?
Back to top
View user's profile Send private message
dthought
Smarty Regular


Joined: 21 Apr 2003
Posts: 55
Location: Melbourne, Australia

PostPosted: Mon Mar 29, 2004 12:52 am    Post subject: Reply with quote

If you want your outputted HTML to be nicely spaced, don't give Smarty tags their own line.

Most logic end tags (eg {/if} etc.) will also attempt to remove a carriage return if one exists directly after it.

So yea, whilst your code might look all beautiful, remember that the logic gets substituted out when the template is compiled... so you have a bunch of space up to where the logic USED to be pre-compilation time, minus its carriage return, and thus added with the padding space of the NEXT line down.

The easiest way to produce pretty outputted HTML is to make your Smarty code a bit harder to read, by mashing it all on as few a lines as possible, along with a single HTML tag. So:

Code:

<tr>
   <th>{$strcolusrrol}</th>
   <td>
      <select name="nivelseguridadid" class="bginput" size="1">
         {foreach item=row from=$niveles}{foreach key=key item=nivel from=$row}{if $key == 'nivelseguridadid'}<option value="{$nivel}" {if $nivel == $usuario.0.nivelseguridadid}selected{/if}>{/if}{if $key == 'descripcion'}{$nivel}</option>
{/if}{/foreach}{/foreach}
      </select>
   </td>
</tr>


Should yield better spaces... sacrificing readability of course. However, in the case of working with SELECT tags, take a look at using Smarty's {html_options} tag, documented in the online manual - it'll save you a *lot* of heartache when using select / option form elements.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Mar 29, 2004 2:24 pm    Post subject: Reply with quote

You can also use {strip}{/strip} to keep the templates clean and spacing minimized in the output, that usually works well with HTML.
Back to top
View user's profile Send private message Visit poster's website
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 -> Bugs 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