2

According to this article a good theme should have "no .phtml template files, except for those that were modified to support the new theme. (Usually this number will be very small.)"

So in an ideal world we could accomplish anything we need by modifying only CSS and the local.xml for a theme.

In the real world though, every client ends up requesting something that I end up having to modify the phtml templates to achieve.

For example, a client is working with a 3rd party company that has asked me to put a div in a very specific spot:

<?php echo $this->getChildHtml('global_notices') ?>
<div class="page">
    <?php echo $this->getChildHtml('header') ?>
    <div class="main-container col1-layout">
        {{ The new HTML needs to go here, but there is no getChildHtml call }}
        <div class="main">
            <?php echo $this->getChildHtml('breadcrumbs') ?>
            <div class="col-main">

I see only two options:

  • add a call to $this->getChildHtml('my_block') (This requires modifying 1column.phtml, 2columns-left.phtml, 2columns-right.phtml and 3columns.phtml)
  • add the block as a child of header, then use javascript to append/prepend it to the desired parent div location (This just seems like a hack to me; could cause FOUC)

I ended up going with the first option, but this is not upgrade proof. When/if those templates are changed in a future release, I'll have to manually merge the changes, so this is not an ideal solution to me.

What would you do in this situation?

1

There is no problem with the first option, if you copy the new files to your template you don't have to worry about upgrading. But I suggest to use this files from RWD theme as you have few new blocks:

<?php if ($_leftContent = $this->getChildHtml('left_first')): ?>
 <?php echo $_leftContent;   ?>
<?php endif; ?>

<?php echo $this->getChildHtml('footer_before') ?>

Following the RWD theme I add this block to solve same problem you have, and I use the same template for every project I'm working on so i can easy insert block after header and before content

<?php echo $this->getChildHtml('header_after') ?>
  • I don't quite understand this point: if you copy the new files to your template you don't have to worry about upgrading? What happens if the magento core devs change the template? For example, in the /base/default template, in 1.9, this new call to getChildHtml was added: <?php echo $this->getChildHtml('global_cookie_notice') ?> This code was NOT in the template for 1.8, which means that if I had copied it from 1.8, then updated to 1.9, any new features that rely on this new getChildHtml call will not work. – Eric Seastrand Feb 11 '15 at 19:34
  • Eric, it took them 3 years to do this, since Magento 1.2 there was no changes to template layout only on RWD 1.9, and I don't think there will be any further changes before Magento 2 which uses different template structure – Ahmed Elawadi Feb 12 '15 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.