title: Magento XML using before/after to place blocks hardly ever works
body: <p>I'm a front-end Magento dev, have built quite a few of my own themes and I want to understand Magento's XML block positioning better...</p>
  
  <p>I normally use a <code>local.xml</code> file to manipulate everything, I can define a block as follows:</p>
  
  <pre><code>&lt;cms_index_index&gt;
     &lt;reference name="root"&gt;
        &lt;block type="core/template" name="example_block" as="exampleBlock" template="page/html/example-block.phtml"/&gt;
     &lt;/reference&gt;
  &lt;/cms_index_index&gt;
  </code></pre>
  
  <p>This would create a block on the home page (<code>cms_index_index</code>) and since the block is created one level under <code>root</code>, I would normally call the block by adding:</p>
  
  <pre><code>&lt;?php echo $this-&gt;getChildHtml('exampleBlock') ?&gt;
  </code></pre>
  
  <p>...to <code>1column.phtml</code> (or <code>2columns-left</code>/<code>right.phtml</code>, <code>3columns.phtml</code> etc). The block can be placed on any page by substituting <code>cms_index_index</code> for the appropriate page tag.</p>
  
  <p>I see stuff like the following throughout the core XML files, and in tutorials:</p>
  
  <pre><code>&lt;reference name="root"&gt;
     &lt;block type="core/template" name="example_block" before="content" template="page/html/example-block.phtml"/&gt;
  &lt;/reference&gt;
  </code></pre>
  
  <p><code>content</code> is a block which is part of magento's general page structure and, from what I understand, <code>before="content"</code> should place it where you'd expect, without needing to use <code>getChildHtml('exampleBlock')</code>, so far so good... however, before/after hardly ever seems to work for me, and I frequently find myself resorting to the getChildHtml method as backup, which isn't always ideal, and means editing more .phtml files than necessary. </p>
  
  <p>I've tried:</p>
  
  <pre><code>&lt;reference name="root"&gt;
     &lt;block type="core/template" name="example_block" before="content" template="page/html/example-block.phtml"/&gt;
  &lt;/reference&gt;
  </code></pre>
  
  <p>Nothing appears...</p>
  
  <pre><code>&lt;reference name="root"&gt;
     &lt;block type="core/template" name="example_block" after="header" template="page/html/example-block.phtml"/&gt;
  &lt;/reference&gt;
  </code></pre>
  
  <p>Still nothing.... I'm also aware of using <code>before="-"</code> or <code>after="-"</code> to place something before everything within it's parent block. I occasionally have some luck with that, but generally just get confused and frustrated.</p>
  
  <p>I've googled all over the place for 'magento xml before/after not working' and beginning to wonder if its just me this happens to... can anyone explain when I can and can't use before/after to position blocks? What's wrong with the above examples?</p>
  
  <p>I'm in magento 1.7.0.2 (latest available at time of posting)</p>
  
  <p>The main motivation for this is to reduce the number of core .phtml files I need to edit just to add a <code>getChildHtml()</code>, so if there is another (XML) way to get around this I'd be interested to know...</p>