Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Why are these line breaks being added?

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
jcx1028
Smarty Rookie


Joined: 13 Apr 2012
Posts: 12

PostPosted: Fri Oct 12, 2012 5:26 pm    Post subject: Why are these line breaks being added? Reply with quote

I'm working with an automotive listings script from Flynax, and while I had no problem installing it on one site a few months back, I'm running into issues with a new install of the script on a new site (but same hosting company). Specifically, line breaks are being added to the code that is causing some of the javascript in the admin section to not work properly.

For example, here is a section of one of the program files...

Code:
{rlHook name='apTplListingsTabsArea'}
   
      {include file='blocks'|cat:$smarty.const.RL_DS|cat:'m_block_end.tpl'}
   {else}
   
      <script type="text/javascript">//<![CDATA[
      // collect plans
      var listing_plans = [
         {foreach from=$plans item='plan' name='plans_f'}
            ['{$plan.ID}', '{$plan.name}']{if !$smarty.foreach.plans_f.last},{/if}
         {/foreach}
      ];
      
      var ui = typeof( rl_ui ) != 'undefined' ? '&ui='+rl_ui : '';
      var ui_cat_id = typeof( cur_cat_id ) != 'undefined' ? '&cat_id='+cur_cat_id : '';
      
      /* read cookies filters */
      var cookies_filters = false;
      
      if ( readCookie('listings_sc') )
         cookies_filters = readCookie('listings_sc').split(',');


...and here's what's showing up in the source code...

Code:
<script type="text/javascript">//<![CDATA[

      // collect plans

      var listing_plans = [

         
            ['1
', 'Bronze Plan
'],
         
            ['4
', 'Gold plan
'],
         
            ['24
', 'Featured package
'],
         
            ['38
', 'Silver plan
'],
         
            ['26
', 'Free Package
']
         
      ];

      

      var ui = typeof( rl_ui ) != 'undefined' ? '&ui='+rl_ui : '';

      var ui_cat_id = typeof( cur_cat_id ) != 'undefined' ? '&cat_id='+cur_cat_id : '';

      

      /* read cookies filters */

      var cookies_filters = false;

      

      if ( readCookie('listings_sc') )

         cookies_filters = readCookie('listings_sc').split(',');


Any idea what could be causing that? Neither Flynax nor my hosting company seem to know for sure.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4636
Location: Hamburg / Germany

PostPosted: Sat Oct 13, 2012 10:05 am    Post subject: Reply with quote

Are you sure that the template files did not srewed up when uploading to the new server?

This looks very strange.....
Back to top
View user's profile Send private message
jeffreydwalter
Smarty n00b


Joined: 26 Oct 2012
Posts: 1

PostPosted: Fri Oct 26, 2012 4:57 am    Post subject: Reply with quote

I'm seeing the same issue with templates. I'm seeing extra whitespace and and newlines.

It would be nice if Smarty would output the html exactly as it's laid out in the file, ignoring the Smarty tags.

Code:

{block name="main_nav"}
<ul class="main-nav">
{foreach $menu_items as $menu_item}
    {if $menu_item.selected}
    <li class="selected"><a href="#" class="{$menu_item.icon}-icn">{$menu_item.text}</a></li>
    {else}
    <li><a href="#" class="{$menu_item.icon}-icn">{$menu_item.text}</a></li>
    {/if}
{/foreach}
</ul>
{/block}


OUTPUT: (Note the whitespace and misalignment of all the html tags.)

Code:


<ul class="main-nav">
    <li class="selected"><a href="#" class="blah.ico-icn">Label</a></li>
       <li><a href="#" class="ha.ico-icn">Another Label</a></li>
    </ul>

   


EXPECTED:

Code:

<ul class="main-nav">
    <li class="selected"><a href="#" class="blah.ico-icn">Label</a></li>
    <li><a href="#" class="ha.ico-icn">Another Label</a></li>
</ul>



This is a trivial example, but here's the general output of a page. I'm using template inheritance and have many blocks. The white space areas are where I have {block} tags (Which don't include that white space in the template.)

This is less than ideal.

Code:



<!DOCTYPE html>
<html lang="en">
    <head>
        <title>$page_title</title>
        <link rel="SHORTCUT ICON" HREF="">

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       

       
        <link rel="stylesheet" type="text/css" href="css/theme.css"/>
       
       

       
   
       
       
    </head>
   
    <body>
       
<header>
   
    <div id="headerLogo" class="header-logo"></div>
   
   
    <ul class="header-nav">
       
               
       
               
       
        <li><button>$log_out_button_text</button></li>
       
    </ul>
   
</header>

       
<nav>
   
<ul class="main-nav">
        <li class="selected"><a href="#" class="blah.ico-icn">Label</a></li>
            <li><a href="#" class="ha.ico-icn">Another Label</a></li>
    </ul>

   
<ul class="secondary-nav">
</ul>

</nav>

       
<div class="content">
    <div class="last-updated"></div>
</div>

       
<footer>
   <button>Woo</button>
   <div class="copyright"><a href="#">About</a></div>
</footer>

    </body>
   
</html>
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4636
Location: Hamburg / Germany

PostPosted: Mon Oct 29, 2012 2:08 pm    Post subject: Reply with quote

Whitespace control on Smarty tags has always been an issue.

Rodney has written an prefilter to solve this

See http://blog.rodneyrehm.de/archives/16-Smarty-Whitespace-Control.html

This will be implemented in the standard syntax of the upcoming Smarty 3.2 release
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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