title: Thymeleaf apply different title-patterns
body: <p>I am using the latest version of <a href="http://www.thymeleaf.org/doc/articles/layouts.html" rel="nofollow noreferrer">thymeleaf page layouts</a>.</p>
  
  <p>I want to use the title pattern <code>$CONTENT_TITLE - $LAYOUT_TITLE</code> for all my pages. Therefore, I created the following layout and content files.</p>
  
  <p>My <code>layout.html</code> file looks like</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
      &lt;title layout:title-pattern="$CONTENT_TITLE - $LAYOUT_TITLE"&gt;My Company Name&lt;/title&gt;
      &lt;!-- some scripts and styles ---&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;!-- some content ---&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My <code>content.html</code> looks like</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
        layout:decorate="~{layout.html}"&gt;
  &lt;head&gt;
      &lt;title&gt;
          &lt;th:block th:if="${meta.pageTitle}" th:text="${meta.pageTitle}"&gt;&lt;/th:block&gt;
      &lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;!-- some content ---&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>If the content page gets <code>Newsletter</code> as value for the property <code>pageTitle</code> and I call the content page in my browser, I get the correct result:</p>
  
  <pre><code>&lt;title&gt;Newsletter - My Company Name&lt;/title&gt;
  </code></pre>
  
  <p>If my content page does not have a title, I only want to display the <code>$LAYOUT_TITLE</code> in my <code>&lt;title&gt;</code> tag without the leading separator <code>-</code>. Howerver, with my code I get</p>
  
  <pre><code>&lt;title&gt;- My Company Name&lt;/title&gt;
  </code></pre>
  
  <p>What I want is</p>
  
  <pre><code>&lt;title&gt;My Company Name&lt;/title&gt;
  </code></pre>
  
  <p>How can I achieve that in a simple way? As far as I know, I cant use the <code>$CONTENT_TITLE</code> in the layout.html and check if it is empty, or can I?</p>