0

I have added a new section to the navigation-sections block in the header, so that I can include it in the mobile menu. The element is displayed correctly, but I cannot change the order of the tabs, to have a new "Welcome" tab show first (by default it shows last). Is there a way of ordering group items?

<block class="Magento\Framework\View\Element\Template" name="store.mobile-welcome" group="navigation-sections" template="Magento_Theme::html/container.phtml" before="store.menu">
    <arguments>
        <argument name="title" translate="true" xsi:type="string">Welcome</argument>
        <argument name="priority" xsi:type="string">1</argument>
    </arguments>
    <block class="Magento\Framework\View\Element\Template" name="store.mobile-welcome-message" template="Magento_Theme::html/mobile-welcome.phtml" />
</block>

I have tried using before="store.menu" and passing a priority argument, and neither are working.

0

I know it's old but may someone want to use it.

<argument name="priority" xsi:type="string">1</argument>

This is OK but you should implement your function in the sections.phtml file as well(DO NOT OVERRIDE CORE FILES) just make a copy and modify it something like this:

<?php
    /**
     * Copyright © 2016 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    // @codingStandardsIgnoreFile
    ?>
    <?php
    /**
     *  General template for displaying group of blocks devided into sections
     */
    $group = $block->getGroupName();
    $groupCss = $block->getGroupCss();
    $groupBehavior = $block->getGroupBehaviour() ? $block->getGroupBehaviour() : '{"tabs":{"openedState":"active"}}';
    ?>
    <?php if ($detailedInfoGroup = $block->getGroupChildNames($group, 'getChildHtml')): ?>
        <div class="sections <?php /* @escapeNotVerified */ echo $groupCss ?>">
            <?php
            $layout = $block->getLayout();
            $newPriority = array();
            ?>
            <div class="section-items <?php /* @escapeNotVerified */ echo $groupCss ?>-items" data-mage-init='<?php /* @escapeNotVerified */ echo $groupBehavior ?>'>
                <?php foreach ($detailedInfoGroup as $name): ?>
                    <?php
                    $html = $layout->renderElement($name);
                    if (!trim($html) && ($block->getUseForce() != true)) {
                        continue;
                    }
                    $alias = $layout->getElementAlias($name);
                    $label = $block->getChildData($alias, 'title');



                    $priority = $block->getChildData($alias, 'priority') ? $block->getChildData($alias, 'priority') : '10';
                    ?>
                               <!-- <div class="section-item-title <?php /* @escapeNotVerified */ echo $groupCss ?>-item-title" data-role="collapsible">
                                    <a class="<?php /* @escapeNotVerified */ echo $groupCss ?>-item-switch" data-toggle="switch" href="#<?php /* @escapeNotVerified */ echo $alias; ?>"><?php /* @escapeNotVerified */ echo $label; ?></a>
                                </div> -->

                    <?php array_push($newPriority, ['alias' => $alias, 'label' => $label, 'priority' => $priority, 'html' => $html]); ?>
                <?php endforeach; ?>

                <?php
                # Sort array by priority
                usort($newPriority, function($a, $b) {
                    return $a['priority'] <=> $b['priority'];
                });
                foreach ($newPriority as $section):
                    ?>
                    <div class="section-item-content <?php /* @escapeNotVerified */ echo $groupCss ?>-item-content" id="<?php /* @escapeNotVerified */ echo $section['alias']; ?>" data-role="content"><?php /* @escapeNotVerified */ echo $section['html']; ?></div>
                <?php endforeach; ?>
            </div>
        </div>
    <?php endif; ?>

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.