title: Chaining smarty templates and clean multiline strings - PHP
body: <p>I know that the first part of this is subjective, but I'd like to hear some different techniques people use. This is a two part question: what do you use for complex multiline strings in PHP? And, can I use a composition type of relationship with smarty?</p>
  
  <p>Question 1: I know there is heredoc and the "." operator. I'm looking for fresh, more readable ideas if there are any.</p>
  
  <p>Question 2: To be more specific, here is what I would like to do with smarty.</p>
  
  <p>Say I have a template, base.tpl:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;title&gt;&lt;/title&gt;&lt;/head&gt;
  &lt;body&gt;
  {$main_content}
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Can I chain templates, i.e. another template that represents $main_content, say main.tpl:</p>
  
  <pre><code>&lt;div id="header"&gt;$header&lt;/div&gt;
  &lt;div id="container"&gt;
  &lt;h1&gt;{$first_header}&lt;/h1&gt;
  &lt;p&gt;{$first_paragraph}&lt;/p&gt;
  &lt;h1&gt;{$second_header}&lt;/h1&gt;
  &lt;p&gt;{$second_paragraph}&lt;/p&gt;
  </code></pre>
  
  <p>I want in whatever.php to load one template into the other, so i.e.:</p>
  
  <pre><code>// ... including smarty and all other boiler plate things ...
  
  $smarty -&gt; assign('first_header', "Foo");
  $smarty -&gt; assign('first_paragraph', "This is a paragraph");
  $smarty -&gt; assign('second_header', "Bar");
  $smarty -&gt; assign('second_paragraph', "This is another paragraph");
  
  $main_content = $smarty-&gt;load('main.tpl');
  $smarty -&gt; display('base.tpl');
  </code></pre>
  
  <p>I know that there is "template inheritance" in smarty, but I'm not familiar with it. Can it give me similar functionality to this?</p>
  
  <p>Note: I think my biggest problem with heredoc is that I can't get syntax highlighting for html (if i specify html in the heredoc string). Without the highlighting, the html that I want to pass through smarty is much harder to read, which kind of defeats the purpose of smarty.</p>