views:

41

answers:

2

I want to keep my templates tidy and nicely intented but would like to deliver only very compact HTML to the browser.
Missing a better idea, I was wondering if there is something wrong with wrapping whole Smarty templates in {strip} tags like so?

{strip}
        <div class="albums">
            <h2>Alle Foto-Alben</h2>

            <ul class="photos clearfix">
                {foreach $albums as $album}
                    {if $album->publishedPhotos|count > 0}
                    <li>
                        <div>
                            <a href="album.php?id={$album->id}">
                                <img src="{$album->titlepic->thumb}" alt="{$album->titlepic->title}" />
                                <span class="title">{$album->title}</span>
                                <span class="counter">{$album->publishedPhotos|count} Foto{if $album->publishedPhotos|count != 1}s{/if}</span>
                            </a>
                        </div>
                    </li>
                    {/if}
                {/foreach}
            </ul>
        </div>
{/strip}

It smells a bit unprofessional to me but I could not come up with something better.
One downside definitely is that you have to wrap every single one of your templates in those tags.

I'm happy to be corrected and would love to hear different approaches to keeping delivered code compact.

A: 

Nope, there's nothing wrong with this.

Do it in a header/footer pair of templates, rather than wrapping each page individually.

Alternately, you could trigger the stripping on the PHP side of things.

Borealid
Thanks for your answer.The header/footer thing doesn't work, though. I'm displaying those templates separately so the start-`{strip}` from `head.tpl` is not compiled in `index.tpl` anymore (or am I wrong)? $smarty->display('_inc/tpl.head.tpl'); $smarty->display('index.tpl'); $smarty->display('_inc/tpl.foot.tpl');
Matze
@Matze: No, you're right, if they're in separate independently-displayed templates, `{strip}` won't work. You can glom the templates together before display, though, and then it will.
Borealid
A: 

Notice: Striptags will ignore includes. Free tip of the day. :-)

Ronn0