bodacydo
bodacydo

Reputation: 79299

How to get rid of whitespace in Smarty {block}s?

I've run into a problem where defining the value of a {block} introduces a lot of unnecessary whitespace.

I've a main template, let's call it main.html, which looks like this (simplified):

<html>
<title>{block name=title}{$default_title}{/block}</title>
...
</html>

Then I inherit from it in let's say topics.html, and I define the title block in it:

{extends file="main.html"}

{block title}
{if $topic}
  {if $topic == "all"}
    {eval $Config['titles']['topics']['all']}
  {else}
    {eval $Config['titles']['topics']['particular']}
  {/if}
{else}
  {eval $Config['titles']['topics']['list']}
{/if}
{/block}

Now when I compile the topics.html template, there is so much whitespace inside of <title>...</title> tag.

For example, it looks like this:

<title>
    Showing all wiki topics  </title>

How could I trim/strip the whitespace from the result of evaluating a block so it looked like the following:?

<title>Showing all wiki topics</title>

I tried adding {strip}...{/strip} around the {block title}...{/block} like this:

{strip}
{block title}
...
{/block}
{/strip}

But that didn't change anything.

I also tried this:

{block title|strip}
...
{/block}

But that was a syntax error. I also tried this:

{block title|trim}
...
{/block}

But it also was a syntax error.

I also tried:

{block title}
{strip}
...
{/strip}
{/block}

But that didn't help either as I already introduced a new-line after {block title}so it stays there in the compiled template.

Any help appreciated!

Upvotes: 2

Views: 2725

Answers (1)

rodneyrehm
rodneyrehm

Reputation: 13557

As of Smarty 3.1 you cannot wrap {block}s in other constructs. (This might change with Smarty 3.2) Have you tried putting the {strip} tags inside the {block}s? Otherwise have a look at my answer here

Upvotes: 2

Related Questions