0

I have a home landing page that has a Login/Logout button. It's currently static html, but I'm trying to convert it so that the button actually functions same as default login/logout button.

I tried creating a custom template landing-content.phtml and updating my Layout Update XML for my homepage to code below.

<referenceContainer name="page.wrapper">

    <container name="landing-header" label="Landing Header" as="landing-header" htmlTag="div" htmlClass="landing-header">
        <container name="landing-header-container" label="Landing Header Container" as="landing-header-container" htmlTag="div" htmlClass="container">
            <block class="Magento\Cms\Block\Block" name="landing-page-header">
                <arguments>
                    <argument name="block_id" xsi:type="string">landing-page-header</argument>
                </arguments>
            </block>
        </container>
    </container>

    <!--
    <container name="landing-content" label="Landing Content" as="landing-content" htmlTag="div" htmlClass="landing-content-area cf">
        <container name="landing-content-container" label="Landing Content Container" as="landing-content-container" htmlTag="div" htmlClass="container cf">
            <block class="Magento\Cms\Block\Block" name="landing-page-content">
                <arguments>
                    <argument name="block_id" xsi:type="string">landing-page-content</argument>
                </arguments>
            </block>
        </container>
    </container>
    -->

    <container name="landing-content" label="Landing Content" as="landing-content" htmlTag="div" htmlClass="landing-content-area cf">
        <container name="landing-content-container" label="Landing Content Container" as="landing-content-container" htmlTag="div" htmlClass="container cf">
            <block class="Magento\Framework\View\Element\Template" name="landing-page-content" template="Magento_Theme::html/landing-content.phtml"></block>
        </container>
    </container>

    <container name="landing-footer" label="Landing Footer" as="landing-footer" htmlTag="footer" htmlClass="landing-footer">
        <block class="Magento\Cms\Block\Block" name="landing-page-footer">
            <arguments>
                <argument name="block_id" xsi:type="string">landing-page-footer</argument>
            </arguments>
        </block>
    </container>

</referenceContainer>
<referenceContainer name="before.body.end">
            <block class="Magento\Framework\View\Element\Template" name="footer.script" template="Magento_Theme::html/landingpage-script.phtml"/>
</referenceContainer>

Additionally, I added the following snippet of code to my landing page, but got an error:

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

// @codingStandardsIgnoreFile

/** @var $block \Magento\Customer\Block\Account\AuthorizationLink */
$dataPostParam = '';
if ($block->isLoggedIn()) {
  //  $dataPostParam = sprintf(" data-post='%s'", $block->getPostParams());
}
?>
<div class="authorization-link" data-label="<?php echo $block->escapeHtml(__('or')); ?>">
    <a <?php /* @escapeNotVerified */ echo $block->getLinkAttributes(); ?><?php /* @escapeNotVerified */ echo $dataPostParam; ?>>
        <?php echo $block->escapeHtml($block->getLabel()); ?>
    </a>
</div>

What am I missing?

1

Try using Magento\Customer\Block\Account\AuthorizationLink for your block instead of Magento\Framework\View\Element\Template. The reason is that AuthorizationLink has the methods you require while the basic template block does not. Also, you'll need to call $block->getHref() to get the link url to the sign in/out page.

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.