2

To add custom link in newsletter block magento 2 ??enter image description here

5

For add custom link in footer inside newsletter block.You Need to override these file in your custom theme

vendor/magento/module-newsletter/view/frontend/templates/subscribe.phtml.

like this one

app/design/frontend/{PackageName}/{ThemeName}/Magento_Newsletter/templates/subscribe.phtml

<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/** @var \Magento\Newsletter\Block\Subscribe $block */

?>
<div class="block newsletter">
    <div class="title">
        <strong>
            <?= $block->escapeHtml(__('Newsletter')) ?>
        </strong>
    </div>
    <div class="content">
        <form class="form subscribe"
            novalidate
            action="<?= $block->escapeUrl($block->getFormActionUrl()) ?>"
            method="post"
            data-mage-init='{"validation": {"errorClass": "mage-error"}}'
            id="newsletter-validate-detail">
            <div class="field newsletter">
                <a href ="link">link</a>
                <label class="label" for="newsletter"><span><?= $block->escapeHtml(__('Sign Up for sneak peaks and sales!')) ?></span></label>
                <div class="control">
                    <input name="email" type="email" id="newsletter"
                            placeholder="<?= $block->escapeHtmlAttr(__('Enter your email')) ?>"
                            data-validate="{required:true, 'validate-email':true}"/>
                </div>
            </div>
            <div class="actions">
                <button id="subscribe-button-click" class="action subscribe primary" title="<?= $block->escapeHtmlAttr(__('Subscribe')) ?>" type="submit">
                    <span><?= $block->escapeHtml(__('Subscribe')) ?></span>
                </button>
            </div>
        </form>
    </div>
</div>

You Add Link Whenever you want in subscribe block as per your html. i have add a link before the newsletter block.PLease check and let me know in case of any issue.

3

Copy subscribe.phtml file form

vendor/magento/module-newsletter/view/frontend/templates/

and paste to you custom theme at following location

app/design/frontend/<vendor name>/<theme name>/Magento_Newsletter/templates/

Now add custom link to subscribe.phtml file

I hope this will help you

3

you can override below file in your theme and update footer container also add custom link

    <?xml version="1.0"?> 
<page xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body>
 <referenceContainer name="footer"> 
     <referenceBlock name="form.subscribe"> 
        <block class="vendor\module\Block\Navigation\Customer" after="-" name="vendor_accountr_footer" template="footer/custom.phtml"/> 
        <block class="Magento\Framework\View\Element\Html\Link" name="custom-link">
                <arguments>
                  <argument name="label" xsi:type="string">Custom Link</argument>
                  <!-- This will be displayed as the label of the link -->
                  <argument name="path" xsi:type="string">path/to/page</argument>
                  <!-- here give the path where the link redirect to -->
                </arguments>
        </block>
    </referenceBlock> 
 </referenceContainer> 
 </body> 
</page>
  • <?xml version="1.0"?> <page xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="footer"> <referenceBlock name="form.subscribe"> <block class="vendor\module\Block\Navigation\Customer" after="-" name="vendor_accountr_footer" template="footer/custom.phtml"/> </referenceBlock> </referenceContainer> </body> </page> – Gomathi Mar 5 at 12:26
  • i want to add link inside newsletter block in app/code itself – Gomathi Mar 5 at 12:27
  • i have added first code this code worked code – Rakesh Donga Mar 5 at 12:29
  • Let me know if you have any confusion for implementation. – Rakesh Donga Mar 5 at 12:31
  • actually i dnt want to override template through design , just from code itself i need to add link inside newsletter block – Gomathi Mar 5 at 12:33
1

In order to call links and custom block in footer in magento 2.

So, the file which is used to define configurations of footer is default.xml. This file will be located under app/code/Namespace/Module/view/frontend/layout/. This file calls on every page, that’s why we write code for footer in this file.

Below code is used to call custom links in footer :

<referenceBlock name="footer_links">
<block class="Magento\Framework\View\Element\Html\Link" name="custom-link">
<arguments>
  <argument name="label" xsi:type="string">Custom Link</argument>
  <!-- This will be displayed as the label of the link -->
  <argument name="path" xsi:type="string">path/to/page</argument>
  <!-- here give the path where the link redirect to -->
</arguments>
</block>
</referenceBlock>

Now If you want to add your own custom block and template inside the footer, then below code will be used :

<referenceContainer name="footer-container">
<block class="Magento\Theme\Block\Html\Footer" name="custom_block" as="custom_block" template="custom.phtml"/>
</referenceContainer>

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.