Is something wrong with wrapping whole Smarty templates in {strip} tags?
I want to keep my templates tidy and nicely intented but would like to deliver only very compact开发者_如何学Python 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.
While it's not wrong i would suggest using a pre-filter instead. A pre-filter only runs when the template is compiling (so it doesn't slow down the server) and you don't need to wrap every template in {strip}. The following rows of code is taken from a project I am working on. It effectively strips most whitespace.
/* Minify the html */
function smarty_pre_minify($tpl_source, $smarty) { return preg_replace('/[ \t\n\r]+/s', ' ', $tpl_source); }
$smarty->registerFilter('pre', 'smarty_pre_minify');
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.
Notice: Striptags will ignore includes. Free tip of the day. :-)
精彩评论