If condition but not else?

1,750 views
Skip to first unread message

Leandro Poblet

unread,
Dec 26, 2011, 6:58:31 PM12/26/11
to Tumblr Themes
Hello,

I've been looking this everywhere in the docs of how to create a
custom theme, but I can't seem to find it. Is there a way to say "If
such condition can't be done, do else, and if else can't be done, go
to default"?

Thanks for your attention and have a nice day!

Sean Zhu

unread,
Dec 29, 2011, 1:51:06 PM12/29/11
to tumblr...@googlegroups.com
You're asking for if…else if…else conditional statements. Tumblr doesn't have exactly those, but it has something else that may do what you're looking for: conditional blocksThe Tumblr theme docs shows you two ways of getting them.

1. There are a few blocks that are conditional blocks — they only get rendered if a condition is true. For example:
  • Everything in {block:SearchPage}…{/block:SearchPage} is rendered if the page is a search results page.
  • Everything in {block:IndexPage}…{/block:IndexPage} is rendered if the page contains multiple posts (tag page, day page, the home page, etc.).
  • Everything in {block:PermalinkPage}…{/block:PermalinkPage} is rendered if the page contains a single "post" (post permalink pages and static pages).

2. You can also create your own conditional blocks that the user can turn on and off via appearance options. Here's the example Tumblr gave (search for "boolean" in the theme docs):
<html>
    <head>
        <!-- DEFAULTS -->
        <meta name="if:Show people I follow" content="1"/>
        <meta name="if:Reverse pagination" content="0"/>
    </head>
    <body>
        {block:IfNotReversePagination}
            <a href="...">Previous</a> <a href="...">Next</a>
        {/block:IfNotReversePagination}
        {block:IfReversePagination}
            <a href="...">Next</a> <a href="...">Previous</a>
        {/block:IfReversePagination}
        {block:IfShowPeopleIFollow}
            <div id="following">...</div>
        {/block:IfShowPeopleIFollow}
    </body>
</html>

In addition you can create conditional blocks based on whether an appearance option is filled out or empty. In Redux (the default Tumblr theme):
{block:IfHeaderImage}<img src="{image:Header}" />{/block:IfHeaderImage}
{block:IfNotHeaderImage}{Title}{/block:IfNotHeaderImage}
The first line is rendered if the user uploaded a header image in appearance options. If not, the second line is rendered.

There are no else if blocks or else blocks. Just if's and sometimes if not's. I hope this answers your question.
Reply all
Reply to author
Forward
0 new messages