6

I'm new to Magento. I'm using Magento 2 Community Edition and I'm trying to get the newsletter subscriber form in the footer, but for some reason, it doesn't appear.

How should I do that?

2 Answers 2

13

I'm not 100% sure what you mean by 'get', I thought you meant add it but as it's already there in the blank and Luma theme and the previous answer is pretty much correct I presume you want to move it so I'll base my answer on that.

Quick answer:

<move element="form.subscribe" destination="*DESTINATION-HERE*" />

The explanation:

Find the block name

First you need to find the name of the block you want to move, to do this I searched all of Magento's module and theme XML files for 'newsletter', to do this I used the following search term vendor/magento/**/frontend/**/*.xml. With enough experience you'll know off the top of your heard that it's subscribe.phtml so it does get easier with time. This returned quite a few files, the one that is responsible for adding the footer newsletter block is vendor/magento/module-newsletter/view/frontend/layout/default.xml. This is the code that renders the block:

<referenceContainer name="footer">
    <block class="Magento\Newsletter\Block\Subscribe" name="form.subscribe" as="subscribe" before="-" template="subscribe.phtml"/>
</referenceContainer>

Move the block

Now we know the block name, we can move it. To do this we use this code:

<move element="*BLOCK-NAME-TO-MOVE*" destination="*DESTING-BLOCK-OR-CONTAINER-NAME*" />

So inside app/design/frontend/*PACKAGE-NAME*/*THEME-NAME*/Magento_Theme/layout/default.xml we can move the block, like so:

<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <move element="form.subscribe" destination="content" />
    </body>
</page>

In the above example the newsletter signup form will be moved to the content, you can swap content with any block or container you wish to place it in.

Screenshot

enter image description here

If you did want to add it to a new theme:

If you did actually mean add it then paste the below code into app/design/frontend/STORE-NAME/THEME-NAME/Magento_Theme/layout/default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>

        <referenceContainer name="footer">
            <block class="Magento\Newsletter\Block\Subscribe" name="form.subscribe" as="subscribe" before="-" template="subscribe.phtml"/>
        </referenceContainer>

    </body>
</page>
1
  • Hi Ben , your solution works very well for my template ! Thank you for your time , now I'm trying to get working also the double minicart , I will let you know how it goes..
    – alexcr
    Apr 25, 2016 at 12:51
3

if you are creating your own them in

view/frontend/layout/default.xml

put tag like this

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
<referenceContainer name="footer">
            <block class="Magento\Newsletter\Block\Subscribe" name="form.subscribe" as="subscribe" before="-" template="subscribe.phtml"/>
        </referenceContainer>
    </body>
</page>

don't forget to clear your layout cache

hope this will work for you

8
  • Hi liyakat , I've aready tryed like this , cleared the cache , but still nothing..
    – alexcr
    Apr 21, 2016 at 9:51
  • did you configure you theme perfectly. it should work to call newsletter in footer
    – liyakat
    Apr 21, 2016 at 10:30
  • yes it should be configured ok , I'm using Venustheme - Yume by the way..
    – alexcr
    Apr 21, 2016 at 10:34
  • Wouldn't it make more sense to move the block rather than redefine it?
    – Ben Crook
    Apr 22, 2016 at 19:05
  • my purpose to give this for new them not to change place :)
    – liyakat
    Apr 23, 2016 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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