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?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI'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:
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>
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.
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>
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