Search code examples
tumblr

The reason behind {block:Title} in Tumblr theme?


Out of curiosity, what's the reason behind using {block:Title} instead of just {Title}:

{block:Title}
  {Title}
{/block:Title}

I do it because Tumblr tells me to, but was wondering if there was a good reason for it. If it's to run conditionally (i.e. to show title when there is one), wouldn't {Title} alone suffice since it's a variable, as it displays nothing when there is no title?


Solution

  • What's the blocking point?

    If it's to run conditionally (i.e. to show title when there is one), wouldn't {Title} alone suffice since it's a variable (i.e. it displays nothing when there is no title)?

    Whilst strictly true, as no string is rendered if no title exists, markup will still be rendered. For example, lets pretend the title is empty.

    Markup

    <h2>{Title}</h2> 
    

    Output

    <h2></h2>
    

    This would be undesired. However, combine title with {block:Title}.

    Markup

    {block:Title}    
    <h2>{Title}</h2> 
    {/block:Title}
    

    Output

    <!--nothing to see-->
    

    tl;dr - Always use the blocks, to stop empty elements being created.