Magento2 Sidebar – How to Sort Order of Custom Blocks

magento2sidebarstatic-block

I have used following code to insert custom blocks in sidebar.

but those are coming in the last of sidebar.i want first custom block-1 then layered navigation then custom block-2 etc.

   <?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <body>           
       <referenceContainer name="sidebar.additional">
           <block class="Magento\Cms\Block\Block" name="useourfinder" before="-">
               <arguments>
                    <argument name="block_id" xsi:type="string">useourfinder</argument>
               </arguments>
           </block>
        </referenceContainer>        <referenceContainer name="sidebar.additional">
           <block class="Magento\Cms\Block\Block" name="sandiego">
               <arguments>
                    <argument name="block_id" xsi:type="string">sandiego</argument>
               </arguments>
           </block>
        </referenceContainer>
   </body>
</page>

Best Answer

You can use after or before while adding block. Something like following...

<block class="Magento\Store\Block\Switcher" name="store_switcher" as="store_switcher" after="footer_links" template="switch/stores.phtml"/>

For example, here I used after attribute to add that block after footer_links block.