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?

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 01:21:13
Script start
Timing: Jan 31 2025 01:21:13
Module start 'layout'
Timing: Jan 31 2025 01:21:13
Module start 'content'
Timing: Jan 31 2025 01:21:13
Module end 'content'
Timing: Jan 31 2025 01:21:13
Script end

Main resources:

Total runtime0.0239 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0039 589.6953151.2109
Module start 'layout' 0.00390.0037 740.9063220.6875
Module start 'content' 0.00760.0148 961.59381,005.9297
Module end 'content' 0.02240.0015 1,967.523437.9922
Script end 0.0239  2,005.5156 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002610.7806140.0002
Check MTime0.00103.9951140.0001
Mysql Total
Database connection0.00041.499310.0004
Mysqli_queries0.00198.008030.0006
Looping result0.00000.046810.0000
Template Total0.00114.410.0011
Template load0.00083.532110.0008
Template processing0.00020.885010.0002
Override
Cache load0.00062.459010.0006
General
dbfile0.002610.851380.0003
String conversion0.00000.033840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs