2

I have a theme that I extended from Luma, I have verified that it is extended properly and working well. I am able to override template/layouts just fine.

I am trying to alter the home page footer links. If I go into

vendor/magento/module-theme/view/frontend/layout/default.xml

I can see the following code for the footer_links.

<referenceContainer name="footer-container">
    <container name="footer" as="footer" label="Page Footer" htmlTag="div" htmlClass="footer content">
        <block class="Magento\Store\Block\Switcher" name="store_switcher" as="store_switcher" template="switch/stores.phtml"/>
        <block class="Magento\Framework\View\Element\Html\Links" name="footer_links">
            <arguments>
                <argument name="css_class" xsi:type="string">footer links</argument>
            </arguments>
        </block>
        <block class="Magento\Theme\Block\Html\Footer" name="copyright" template="html/copyright.phtml"/>
        <block class="Magento\Framework\View\Element\Template" name="report.bugs" template="Magento_Theme::html/bugreport.phtml" />
    </container>
</referenceContainer>

When I go to the home page I see the following links.

Links on Page view

However, when I go into the admin backend at Content -> Elements -> Blocks, and edit the block with an id of footer_links_block, I get the following content in the editor.

<ul class="footer links">
    <li class="nav item"><a href="{{store url="about-us"}}">About us</a></li>
    <li class="nav item"><a href="{{store url="customer-service"}}">Customer Service</a></li>
</ul>

UPDATE

To add to my question, inside my file at app/design/frontend/vendor/default I have altered the layout with the following code.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="logo">
            <arguments>
                <argument name="logo_file" xsi:type="string">images/image.jpg</argument>
            </arguments>
        </referenceBlock>

        <referenceContainer name="footer">
            <referenceBlock name="store_switcher" remove="true"/>
            <referenceBlock name="copyright" remove="true"/>
            <referenceBlock name="report.bugs" remove="true"/>
        </referenceContainer>
    </body>
</page>

So I have removed everything in the footer except for the subscribe and the links.

enter image description here

However, the links here are coming from the code. I want to make this editable from the admin side instead. Do I just need to scrap the whole footer and make a custom one? Or is there a way to go to the backend now and edit this?

1

The magento layout system (and any other xml configuration system) is pretty powerful but it may look intimidating at first.
The idea is that all the xml layout files with the same name are merged into one big xml before processing and rendering.
The upside of this is that you can add stuff to a page without having to alter a core module.
The downside is...what you have now. It's not that easy to find what is where.
In this case the block Magento\Framework\View\Element\Html\Links is just a container that can be altered from different layout files.
It just holds a collection of links and displays them in the page.
It does not care what links it holds.
Look in all the layout files for the text referenceBlock name="footer_links" where footer_links is the name of the block.
What you find, it alters the block content.
You will find the contact link in the contact module, advanced search link in the search module and so on.
To generalize... when you need to change the behavior of a block search in the layout files for referenceBlock name="name of the block here" to see what else alters is.

[Edit]

The name of the blocks in the layout file have nothing to do with the names of the static blocks you add in the admin panel.
The names of the blocks from the layout files are used just to know how to reference them in other layout files.
The names (identifiers) of the static blocks you add/edit in the admin are used for retrieving them when needed.

  • Very helpful Marius. I actually did go around and found all the places these links were being added at so I understand all of that. What I am not understanding is that the block in the back end with id footer_links_block, apparently has nothing to do with that same named block in the code. I also found out that I could go and create a widget with that footer_links_block and the content for that will display. I am confused on what I should do in code, and what I should do through authoring I think. Should I remove the footer_links_block from my inherited template? Create a new one? Im lost. – Metropolis Jun 30 '17 at 18:45
  • I updated my question with some more information. – Metropolis Jul 3 '17 at 15:50
0

The links are injected from layout files from vendor/magento/*-module/view/frontend/layout/default.xml

See in contacts module:

<referenceBlock name="footer_links">
        <block class="Magento\Framework\View\Element\Html\Link\Current" ifconfig="contact/contact/enabled" name="contact-us-link">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">Contact Us</argument>
                <argument name="path" xsi:type="string">contact</argument>
            </arguments>
        </block>
    </referenceBlock>

You can remove blocks with: <referenceBlock name="contact-us-link" remove="true" /> in default.xml. The <arguments> are just variables injected in the constructor of the block.

You can add your own links as you see above. In Magento\Framework\View\Element\* there are all kinds of blocks if you don't want to write the template (.phtml) file. And you can create your own reusable blocks if you'd like. Magento\Framework\View\Element\Template is the basic 'template' block that you can use as in the example bellow. In template you can place what you need.

<block class="Magento\Framework\View\Element\Template" name="skip_to_content.target" before="-" template="Magento_Theme::html/skiptarget.phtml">

Please try http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/bk-frontend-dev-guide.html and Alan Storm's articles about frontend. It's a good way to start with.

  • Sorry I am new to magento. What did you mean by "my CMS block doesn't show". You mean that the footer_links block in my admin area is not attached to the block I think it is? – Metropolis Jun 30 '17 at 16:30
  • Okay, I think I see now where the content is coming from. Seems to be coming from a bunch of different modules with each including one link. If these links are all hard coded into the xml files though, then how can this be authored? Do I need to just create a new custom block for my own purposes? – Metropolis Jun 30 '17 at 16:59
  • I updated my answer. If you want to remove some of the links, use the remove="true" XML attribute on <referenceBlock>. – obscure Jun 30 '17 at 20:53
  • Right, I know all of the things I can do inside the templates, and I have read that article already. The thing I am having a problem with is the relationship between the blocks in code, and the way these blocks are authored. For instance, I want to edit the layout of the footer, so I removed everything except the subscribe and footer_links. However, how can that content be authored? – Metropolis Jul 3 '17 at 15:40
  • I updated my question to be a little more specific. – Metropolis Jul 3 '17 at 15:50

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.