Magento 2: Why block initialized but template not rendered?












2















I have a page that I want to add content to it. My problem is that my block is initialized and setTemplate is called but my template never rendered. I tried adding module name to layout (Vendor_Test::) but it made no difference. When I edit my layout, I change the title and clean the cache, so I can see that new title is applied.



Here is my files:



Controller:



<?php
namespace VendorTestControllerExec;

use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppResponseInterface;

class Bank extends MagentoFrameworkAppActionAction
{
protected $resultPageFactory;
public function __construct(
Context $context,
PageFactory $resultPageFactory
)
{
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute()
{
$page = $this->resultPageFactory->create();
return $page;
}
}


My layout:



<?xml version="1.0"?>
<page layout="3column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>Bank Page Title</title>
</head>
<body>
<block class="VendorTestBlockDate" name="vendor.test.date" template="date.phtml" >
<arguments>
<argument name="something" xsi:type="string">Value</argument>
</arguments>
</block>
</body>
</page>


My Block:



<?php 
namespace VendorTestBlock;


class Date extends MagentoFrameworkViewElementTemplate
{
/**
* @param MagentoFrameworkViewElementTemplateContext $context
* @param array $data
*/
public function __construct(MagentoFrameworkViewElementTemplateContext $context, array $data = )
{
parent::__construct($context, $data);
}

public function getDate()
{
return date('m/d/Y H:i:s');
}
}


My template:



<div class="Something" >
<?php echo $block->getDate();?>
</div>


Output:



Output










share|improve this question





























    2















    I have a page that I want to add content to it. My problem is that my block is initialized and setTemplate is called but my template never rendered. I tried adding module name to layout (Vendor_Test::) but it made no difference. When I edit my layout, I change the title and clean the cache, so I can see that new title is applied.



    Here is my files:



    Controller:



    <?php
    namespace VendorTestControllerExec;

    use MagentoFrameworkAppActionContext;
    use MagentoFrameworkViewResultPageFactory;
    use MagentoFrameworkAppResponseInterface;

    class Bank extends MagentoFrameworkAppActionAction
    {
    protected $resultPageFactory;
    public function __construct(
    Context $context,
    PageFactory $resultPageFactory
    )
    {
    $this->resultPageFactory = $resultPageFactory;
    parent::__construct($context);
    }
    public function execute()
    {
    $page = $this->resultPageFactory->create();
    return $page;
    }
    }


    My layout:



    <?xml version="1.0"?>
    <page layout="3column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
    <title>Bank Page Title</title>
    </head>
    <body>
    <block class="VendorTestBlockDate" name="vendor.test.date" template="date.phtml" >
    <arguments>
    <argument name="something" xsi:type="string">Value</argument>
    </arguments>
    </block>
    </body>
    </page>


    My Block:



    <?php 
    namespace VendorTestBlock;


    class Date extends MagentoFrameworkViewElementTemplate
    {
    /**
    * @param MagentoFrameworkViewElementTemplateContext $context
    * @param array $data
    */
    public function __construct(MagentoFrameworkViewElementTemplateContext $context, array $data = )
    {
    parent::__construct($context, $data);
    }

    public function getDate()
    {
    return date('m/d/Y H:i:s');
    }
    }


    My template:



    <div class="Something" >
    <?php echo $block->getDate();?>
    </div>


    Output:



    Output










    share|improve this question



























      2












      2








      2








      I have a page that I want to add content to it. My problem is that my block is initialized and setTemplate is called but my template never rendered. I tried adding module name to layout (Vendor_Test::) but it made no difference. When I edit my layout, I change the title and clean the cache, so I can see that new title is applied.



      Here is my files:



      Controller:



      <?php
      namespace VendorTestControllerExec;

      use MagentoFrameworkAppActionContext;
      use MagentoFrameworkViewResultPageFactory;
      use MagentoFrameworkAppResponseInterface;

      class Bank extends MagentoFrameworkAppActionAction
      {
      protected $resultPageFactory;
      public function __construct(
      Context $context,
      PageFactory $resultPageFactory
      )
      {
      $this->resultPageFactory = $resultPageFactory;
      parent::__construct($context);
      }
      public function execute()
      {
      $page = $this->resultPageFactory->create();
      return $page;
      }
      }


      My layout:



      <?xml version="1.0"?>
      <page layout="3column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <head>
      <title>Bank Page Title</title>
      </head>
      <body>
      <block class="VendorTestBlockDate" name="vendor.test.date" template="date.phtml" >
      <arguments>
      <argument name="something" xsi:type="string">Value</argument>
      </arguments>
      </block>
      </body>
      </page>


      My Block:



      <?php 
      namespace VendorTestBlock;


      class Date extends MagentoFrameworkViewElementTemplate
      {
      /**
      * @param MagentoFrameworkViewElementTemplateContext $context
      * @param array $data
      */
      public function __construct(MagentoFrameworkViewElementTemplateContext $context, array $data = )
      {
      parent::__construct($context, $data);
      }

      public function getDate()
      {
      return date('m/d/Y H:i:s');
      }
      }


      My template:



      <div class="Something" >
      <?php echo $block->getDate();?>
      </div>


      Output:



      Output










      share|improve this question
















      I have a page that I want to add content to it. My problem is that my block is initialized and setTemplate is called but my template never rendered. I tried adding module name to layout (Vendor_Test::) but it made no difference. When I edit my layout, I change the title and clean the cache, so I can see that new title is applied.



      Here is my files:



      Controller:



      <?php
      namespace VendorTestControllerExec;

      use MagentoFrameworkAppActionContext;
      use MagentoFrameworkViewResultPageFactory;
      use MagentoFrameworkAppResponseInterface;

      class Bank extends MagentoFrameworkAppActionAction
      {
      protected $resultPageFactory;
      public function __construct(
      Context $context,
      PageFactory $resultPageFactory
      )
      {
      $this->resultPageFactory = $resultPageFactory;
      parent::__construct($context);
      }
      public function execute()
      {
      $page = $this->resultPageFactory->create();
      return $page;
      }
      }


      My layout:



      <?xml version="1.0"?>
      <page layout="3column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <head>
      <title>Bank Page Title</title>
      </head>
      <body>
      <block class="VendorTestBlockDate" name="vendor.test.date" template="date.phtml" >
      <arguments>
      <argument name="something" xsi:type="string">Value</argument>
      </arguments>
      </block>
      </body>
      </page>


      My Block:



      <?php 
      namespace VendorTestBlock;


      class Date extends MagentoFrameworkViewElementTemplate
      {
      /**
      * @param MagentoFrameworkViewElementTemplateContext $context
      * @param array $data
      */
      public function __construct(MagentoFrameworkViewElementTemplateContext $context, array $data = )
      {
      parent::__construct($context, $data);
      }

      public function getDate()
      {
      return date('m/d/Y H:i:s');
      }
      }


      My template:



      <div class="Something" >
      <?php echo $block->getDate();?>
      </div>


      Output:



      Output







      magento2 layout blocks template xml






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 28 '17 at 12:16









      Rafael Corrêa Gomes

      4,53423264




      4,53423264










      asked May 27 '17 at 22:30









      undoneundone

      2061218




      2061218






















          2 Answers
          2






          active

          oldest

          votes


















          2














          Change your layout file by following code




          <?xml version="1.0"?>
          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
          <head>
          <title>Bank Page Title</title>
          </head>
          <body>
          <referenceContainer name="content">
          <block class="VendorTestBlockDate" name="vendor.test.date" template="Vendor_Test::date.phtml">
          <arguments>
          <argument name="something" xsi:type="string">Value</argument>
          </arguments>
          </block>
          </referenceContainer>
          </body>
          </page>


          Clear cache.






          share|improve this answer
























          • It worked! Can you point to me where was the problem? using 3column? not using referenceContainer?

            – undone
            May 28 '17 at 12:15











          • Check <referenceContainer name="content">

            – Sohel Rana
            May 28 '17 at 13:01











          • Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…

            – Sohel Rana
            May 28 '17 at 13:01



















          0














          In my case, I had some function calls in my template file. As one of the functions which were throwing some error. That was causing the template file from not rendering. So, anything after that function call will not display.





          share








          New contributor




          hardik thakkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "479"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f176348%2fmagento-2-why-block-initialized-but-template-not-rendered%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            Change your layout file by following code




            <?xml version="1.0"?>
            <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <head>
            <title>Bank Page Title</title>
            </head>
            <body>
            <referenceContainer name="content">
            <block class="VendorTestBlockDate" name="vendor.test.date" template="Vendor_Test::date.phtml">
            <arguments>
            <argument name="something" xsi:type="string">Value</argument>
            </arguments>
            </block>
            </referenceContainer>
            </body>
            </page>


            Clear cache.






            share|improve this answer
























            • It worked! Can you point to me where was the problem? using 3column? not using referenceContainer?

              – undone
              May 28 '17 at 12:15











            • Check <referenceContainer name="content">

              – Sohel Rana
              May 28 '17 at 13:01











            • Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…

              – Sohel Rana
              May 28 '17 at 13:01
















            2














            Change your layout file by following code




            <?xml version="1.0"?>
            <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <head>
            <title>Bank Page Title</title>
            </head>
            <body>
            <referenceContainer name="content">
            <block class="VendorTestBlockDate" name="vendor.test.date" template="Vendor_Test::date.phtml">
            <arguments>
            <argument name="something" xsi:type="string">Value</argument>
            </arguments>
            </block>
            </referenceContainer>
            </body>
            </page>


            Clear cache.






            share|improve this answer
























            • It worked! Can you point to me where was the problem? using 3column? not using referenceContainer?

              – undone
              May 28 '17 at 12:15











            • Check <referenceContainer name="content">

              – Sohel Rana
              May 28 '17 at 13:01











            • Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…

              – Sohel Rana
              May 28 '17 at 13:01














            2












            2








            2







            Change your layout file by following code




            <?xml version="1.0"?>
            <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <head>
            <title>Bank Page Title</title>
            </head>
            <body>
            <referenceContainer name="content">
            <block class="VendorTestBlockDate" name="vendor.test.date" template="Vendor_Test::date.phtml">
            <arguments>
            <argument name="something" xsi:type="string">Value</argument>
            </arguments>
            </block>
            </referenceContainer>
            </body>
            </page>


            Clear cache.






            share|improve this answer













            Change your layout file by following code




            <?xml version="1.0"?>
            <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <head>
            <title>Bank Page Title</title>
            </head>
            <body>
            <referenceContainer name="content">
            <block class="VendorTestBlockDate" name="vendor.test.date" template="Vendor_Test::date.phtml">
            <arguments>
            <argument name="something" xsi:type="string">Value</argument>
            </arguments>
            </block>
            </referenceContainer>
            </body>
            </page>


            Clear cache.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 28 '17 at 7:05









            Sohel RanaSohel Rana

            22.4k34460




            22.4k34460













            • It worked! Can you point to me where was the problem? using 3column? not using referenceContainer?

              – undone
              May 28 '17 at 12:15











            • Check <referenceContainer name="content">

              – Sohel Rana
              May 28 '17 at 13:01











            • Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…

              – Sohel Rana
              May 28 '17 at 13:01



















            • It worked! Can you point to me where was the problem? using 3column? not using referenceContainer?

              – undone
              May 28 '17 at 12:15











            • Check <referenceContainer name="content">

              – Sohel Rana
              May 28 '17 at 13:01











            • Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…

              – Sohel Rana
              May 28 '17 at 13:01

















            It worked! Can you point to me where was the problem? using 3column? not using referenceContainer?

            – undone
            May 28 '17 at 12:15





            It worked! Can you point to me where was the problem? using 3column? not using referenceContainer?

            – undone
            May 28 '17 at 12:15













            Check <referenceContainer name="content">

            – Sohel Rana
            May 28 '17 at 13:01





            Check <referenceContainer name="content">

            – Sohel Rana
            May 28 '17 at 13:01













            Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…

            – Sohel Rana
            May 28 '17 at 13:01





            Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…

            – Sohel Rana
            May 28 '17 at 13:01













            0














            In my case, I had some function calls in my template file. As one of the functions which were throwing some error. That was causing the template file from not rendering. So, anything after that function call will not display.





            share








            New contributor




            hardik thakkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.

























              0














              In my case, I had some function calls in my template file. As one of the functions which were throwing some error. That was causing the template file from not rendering. So, anything after that function call will not display.





              share








              New contributor




              hardik thakkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.























                0












                0








                0







                In my case, I had some function calls in my template file. As one of the functions which were throwing some error. That was causing the template file from not rendering. So, anything after that function call will not display.





                share








                New contributor




                hardik thakkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.










                In my case, I had some function calls in my template file. As one of the functions which were throwing some error. That was causing the template file from not rendering. So, anything after that function call will not display.






                share








                New contributor




                hardik thakkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.








                share


                share






                New contributor




                hardik thakkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered 4 mins ago









                hardik thakkarhardik thakkar

                1




                1




                New contributor




                hardik thakkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                hardik thakkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                hardik thakkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f176348%2fmagento-2-why-block-initialized-but-template-not-rendered%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    What other Star Trek series did the main TNG cast show up in?

                    Berlina muro

                    Berlina aerponto