Forums / Developer / Lots of 'sections' and html whitespace

Lots of 'sections' and html whitespace

Author Message

Paul Forsyth

Friday 20 February 2004 4:17:00 am

Im adding logic to my templates for some situations, and when i look at the html source im finding it to contain lots of extra whitespace, which i believe are due to the many section/section-else statements. I've removed any tabs i have and the only whitespace remaining are normal spaces and new lines.

After removing such whitespace (making a huge single line) the html produced is what i expect.

So, is there a way to eliminate the indentions caused by logic code through the changing of a template? From the cause/effect experiments i've tried this seems to a lib/kernel issue.

Paul

Alex Jones

Friday 20 February 2004 6:42:40 am

A new whitespace wash operator would be nice. I recall an old thread that discussed it, but apparently the idea went no further than that: http://ez.no/community/forum/suggestions/nowhitespace_template_operator

I would really like the ability to format my eZ code so it is easy to read, without sacrificing the resulting HTML source.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Friday 20 February 2004 7:09:06 am

Pasted here from:

http://ez.no/community/bug_reports/template_logic_code_shouldn_t_produce_whitespace

to use the code tag!

            {section var=menu loop=$mainMenu}
                {section show=eq($menu.item.id, $menu_home_node)}
                     {set menu_url_alias="/"}
                {section-else}
                     {set menu_url_alias=$menu.item.url_alias}
                {/section}
                {section show=$menu.item.is_selected}
                    {* Only show the selection image if the current node is the same as the menu item *}
                    {section show=eq($node_id,$menu.item.id)}
                        {* If the current node is the last selection show the border *}
                        {section show=eq($menu.item.id,$last_selected_node)}
<li class="menu_link_level_{$menu.item.level}_selected"><a href={$menu_url_alias|ezurl}>{$menu.item.menu_name}</a></li>

Marko Pohl

Friday 20 February 2004 7:13:40 am

I would appreciate this opperator too.
I use this kind often when coding with the smarty template engine.
They use the tags {strip}{/strip} to eleminate whitespaces between the tags.

Area51 Mcb

Saturday 08 September 2007 5:25:55 am

Hi, I'm having the same problem, has anyone found a solution to this issue?
Unless I don't indent the code in the templates, the html source contains empty lines and spaces.

Thanks in advance.

Stéphane Bullier

Sunday 09 September 2007 12:18:07 am

Hello,

You have this setting for site.ini : UseFormatting

http://ez.no/doc/ez_publish/technical_manual/3_9/reference/configuration_files/site_ini/templatesettings/useformatting

Stéphane

Area51 Mcb

Monday 10 September 2007 12:43:41 am

Thank you for your reply.
I tried to enable / disable the UseFormatting setting, but it doesn't seem to do the trick. Well, I should say, I don't see any difference in the html source.
(The setting TemplateCompile is enabled though.)

When I first changed the UseFormatting setting, ezP generated bad code in the compiled templates. (I'm using ezP 3.9.2)

I got an unexpected T_String error, so I had to look into the compiled templates.

The content of $variableNameText in line 2698 of /lib/eztemplate/classes/eztemplatecompiler.php contains double quotes, resulting in something like this:

$tpl->warning("Variable "testvar" is already define.");

The original code of eztemplatecompiler.php

$php->addCodePiece( "    \$tpl->warning( '" . EZ_TEMPLATE_DEF_FUNCTION_NAME . "', \"Variable $variableNameText is already defined.\" );\n" );

I used a quick fix to replace double quotes by single quotes, to prevent this

$php->addCodePiece( "    \$tpl->warning( '" . EZ_TEMPLATE_DEF_FUNCTION_NAME . "', \"Variable ".str_replace("\"", "'", $variableNameText)." is already defined.\" );\n" );

Now the generated code should look like this:

$tpl->warning("Variable 'testvar' is already define.");

Not sure why this bug suddenly appeared when changing the UseFormatting setting, but anyway, with this fixed, I'm still having empty lines and whitespace in the html source.
Is there something else other than TemplateCompile that could have effect on UseFormatting?