2

I added custom link in header tab example chat, if i click this link move one custom form, but, its only show only 1column layout, form not showing. what I miss this code.

This is my layout File:

<?xml version="1.0"?>

 <page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-  instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

  <body>
    <referenceContainer name="content">
    <block class="ChennaiBox\Chat\Block\ChatBlock" template="ChennaiBox_Chat::ChatForm.phtml"/>
    </referenceContainer>

  </body>
  </page>

This is My Block:

 <?php

  namespace ChennaiBox\Chat\Block;
  class ChatBlock extends \Magento\Framework\View\Element\Template  
   {


   }

This is Template File:

 <?php?>
<h1>Chat</h1>

This is my default.xml layout:

  <?xml version="1.0"?>

  <page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="default_head_blocks"/>
     <body>
      <move element="Chat_link" destination="header.links"/>
        <referenceContainer name="header.panel">
        <block class="Magento\Framework\View\Element\Html\Link\Current" name="Chat_link">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">Chat</argument>
                <argument name="path" xsi:type="string">chennaibox/livechat/livechat</argument>
            </arguments>
           </block> 
 </referenceContainer>
 </body>
 </page>

This is my controller:

 <?php

 namespace ChennaiBox\Chat\Controller\LiveChat;
  class LiveChat extends \Magento\Framework\App\Action\Action
   {

 protected $resultPageFactory;

 public function __construct(\Magento\Framework\App\Action\Context $context, \Magento\Framework\View\Result\PageFactory $page)
    {
      parent::__construct($context);
      $this->resultPageFactory = $page;       
    }
public function execute()
{
    $resultPage = $this->resultPageFactory->create();
    return $resultPage;

   //echo "This is my test";
}

}

I need to print "Chat" word in layout, but its only show 1 column layout what i miss. suggest me how to do this...

2
  • you have to define layout="3columns" in your xml file at first you have displayed May 17, 2016 at 9:08
  • yes, my layout file working , then only show chat link in header panel May 17, 2016 at 9:24

1 Answer 1

2

You can just 3columns in your layout file instead of 1column.

Try below code,

<?xml version="1.0"?>

  <page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="default_head_blocks"/>
     <body>
        <referenceContainer name="header.panel">
        <block class="ChennaiBox\Chat\Block\ChatBlock" name="Chat_link">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">Chat</argument>
                <argument name="path" xsi:type="string">chennaibox/livechat/livechat</argument>
            </arguments>
           </block> 

      <move element="Chat_link" destination="header.links"/>
 </referenceContainer>
 </body>
 </page>

inside your block,

ChatBlock.php file,

namespace ChennaiBox\Chat\Block;

/**
 * Class Link
 *
 * @SuppressWarnings(PHPMD.DepthOfInheritance)
 */
class ChatBlock extends \Magento\Framework\View\Element\Html\Link
{
    protected $_template = 'ChennaiBox_Chat::ChatForm.phtml';    



    public function getLabel()
    {        
        return __('Chat');
    }
}
8
  • My layout is working but, my template not working for me , it show, invalid template file. May 17, 2016 at 10:04
  • where you have define your template path? May 17, 2016 at 10:09
  • My default.xml file, i wrote in my custom theme file, my custom theme extends luma theme, but, my bllock and template content i wrote cutom module, they have any problem... but, i mentioned path of block in default.xml file. May 17, 2016 at 10:12
  • plz show your default.xml file May 17, 2016 at 10:13
  • I added Above in the list " default.xml" file... May 17, 2016 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.