3

EDIT: SOLVED, see answer below (will accept when I can).

I wanted to move the newsletter block on the frontend of my site to the footer.

So I changed this in newsletter.xml: ( Previously the reference was <reference name="left">)

    <!-- Mage_Newsletter -->
    <reference name="footer">
        <block type="newsletter/subscribe" name="footer.newsletter" template="newsletter/subscribe.phtml"/>
    </reference>

This has worked in that the newsletter has moved to the footer, but how can I control where the block is positioned within the footer.

I tried this in my templates ... page/html/footer.phtml:

<div class="footer-container">
    <footer class="footer">
        <div class="row">
            <div class="nine columns">
                <?php echo $this->getChildHtml() ?>
            </div>
            <div class="three columns">
                <?php echo $this->getChildHtml('footer.newsletter') ?>
            </div>
        </div>
...

But this duplicates the newsletter block. Now it appears once in the place I want it to be (in the three-column div) but then appears again in the nine-column div.

I assume this is because it is included in the '$this->getChildHtml()' call.

I would really appreciate any help, thanks. Definitely missing a trick somewhere.

4

Just add below single line & it works

<?php echo $this->getLayout()->createBlock('newsletter/subscribe')->setTemplate('newsletter/subscribe.phtml')->toHtml(); ?>
3

Try to use after or before attribute:

<reference name="footer">
    <block type="newsletter/subscribe" name="footer.newsletter" after="footer_links" template="newsletter/subscribe.phtml"/>
</reference>
  • Hi, I had tried the before attribute before but no change. I think the problem was that the newsletter was included as a child block of footer so was printing out there too (in the nine column div). I have changed the 'getChildHtml()' to be 'getChildHtml(cms_footer_links')' as that is the only block I want to be called in this area anyway. – Sarah Jan 28 '14 at 14:48
  • Did you tried before="cms_footer_links"? And did you clear all cache? – oleksii.svarychevskyi Jan 28 '14 at 14:54
  • I haven't tried this but I suspect it would mean the block would appear once above the footer links and then again where I have called it in the HTML. The issues was the call 'getChildHtml()' which was getting ALL child blocks, in addition to my call 'getChildHtml('footer.newsletter')' which was getting the newsletter block again, so of course they were showing twice. Anyway I have solved my problem, thanks for your help! – Sarah Jan 29 '14 at 12:32
2

The problem was the getChildHtml() call which as far as I understand was printing out ALL blocks in footer, so of course it was printing out the newsletter block in that call. And then my call getChildHtml('footer.newsletter') was printing the newsletter block again.

I changed getChildHtml() to getChildHtml('cms_footer_links') and now that is the only block showing there (which is what I wanted anyway).

  • 1
    But it's not the best way to do. You can delete all unnecessary blocks with layout xml. <remove name="block_name"> – oleksii.svarychevskyi Jan 29 '14 at 12:37
  • But if I <remove name="footer.newsletter"> that means the footer will not show anywhere. – Sarah Jan 29 '14 at 12:49
  • Why all footer? Only block which you mention. – oleksii.svarychevskyi Jan 29 '14 at 12:51
  • Sorry I meant "that means the newsletter block will not show anywhere". If I remove the newsletter block using <remove name="footer.newsletter">, the newsletter will not show when I call getChildHtml('footer.newsletter') in the place where I want it to appear, as it does now. – Sarah Jan 29 '14 at 17:25

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.