2

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!

4

1 回答 1

2

从 Smarty 3.1 开始,您不能将{block}s 包装在其他构造中。(这可能会随着 Smarty 3.2 改变)你有没有试过把{strip}标签放在里面{block}s?否则在这里看看我的回答

于 2012-06-17T14:43:04.737 回答