Magento 2 setTemplate and add content to phtml templateInclude phtml in magento CMSHow to change admin login template in Magento 1.5 or 1.6Add template block into another templateHow Can A Block Render Without Specifying `as` property of the block, When we use getChildHtml() MethodMagento 2 html file and phtml file in custom template process?Magento2: Add custom template to product details page below add to cart sectionAdd customer session object and use in templatesMagento 2 add custom data to checkoutMagento 2.2 can't override default templateHelp with overwriting .phtml file in Magento 2.2.7

What is the status of the F-1B engine development?

Why aren't rainbows blurred-out into nothing after they are produced?

Does the Fireball spell damage objects?

What is this "Table of astronomy" about?

How many people would you need to pull a whale over cobblestone streets?

Generate Brainfuck for the numbers 1–255

If "more guns less crime", how do gun advocates explain that the EU has less crime than the US?

How much maintenance time did it take to make an F4U Corsair ready for another flight?

How to create events observer that only call when REST api dispatch events?

Do beef farmed pastures net remove carbon emissions?

Plotting octahedron inside the sphere and sphere inside the cube

Understanding this peak detector circuit

When were the tantalum capacitors first used in computing?

Is it okay for a ticket seller in the USA to refuse to give you your change, keep it for themselves and claim it's a tip?

Email address etiquette - Which address should I use to contact professors?

What should I call bands of armed men in the Middle Ages?

Is there a standardised way to check fake news?

How to remove ambiguity: "... lives in the city of H, the capital of the province of NS, WHERE the unemployment rate is ..."?

Can sampling rate be a floating point number?

80's/90's superhero cartoon with a man on fire and a man who made ice runways like Frozone

Super Duper Vdd stiffening required on 555 timer, what is the best way?

Is it feasible to get a hash collision for CRC32, MD-5 and SHA-1 on one file?

How to divide item stack in MC PE?

These were just lying around



Magento 2 setTemplate and add content to phtml template


Include phtml in magento CMSHow to change admin login template in Magento 1.5 or 1.6Add template block into another templateHow Can A Block Render Without Specifying `as` property of the block, When we use getChildHtml() MethodMagento 2 html file and phtml file in custom template process?Magento2: Add custom template to product details page below add to cart sectionAdd customer session object and use in templatesMagento 2 add custom data to checkoutMagento 2.2 can't override default templateHelp with overwriting .phtml file in Magento 2.2.7






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















How to add bare HTML to a block e.g:



$block = $result->getLayout()->getBlock('category.description');
$block->setTemplate('Vendor_Module::myTemplate/blank.phtml')
->toHtml('<p>My Content</p>');


Is there a way to dynamically add content to a block perhaps without use of templates or any other way appreciate?










share|improve this question
































    1















    How to add bare HTML to a block e.g:



    $block = $result->getLayout()->getBlock('category.description');
    $block->setTemplate('Vendor_Module::myTemplate/blank.phtml')
    ->toHtml('<p>My Content</p>');


    Is there a way to dynamically add content to a block perhaps without use of templates or any other way appreciate?










    share|improve this question




























      1












      1








      1








      How to add bare HTML to a block e.g:



      $block = $result->getLayout()->getBlock('category.description');
      $block->setTemplate('Vendor_Module::myTemplate/blank.phtml')
      ->toHtml('<p>My Content</p>');


      Is there a way to dynamically add content to a block perhaps without use of templates or any other way appreciate?










      share|improve this question
















      How to add bare HTML to a block e.g:



      $block = $result->getLayout()->getBlock('category.description');
      $block->setTemplate('Vendor_Module::myTemplate/blank.phtml')
      ->toHtml('<p>My Content</p>');


      Is there a way to dynamically add content to a block perhaps without use of templates or any other way appreciate?







      layout template magento2.2.2 template-override






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 1 at 11:19









      Waqar Ali

      59616 bronze badges




      59616 bronze badges










      asked Aug 1 at 11:04









      Juliano VargasJuliano Vargas

      7616 silver badges27 bronze badges




      7616 silver badges27 bronze badges























          2 Answers
          2






          active

          oldest

          votes


















          3














          You should try this



           echo $this->getLayout()->createBlock("VendorModuleBlockMyblock")- 
          >setTemplate("My_Module::history-suite.phtml")->toHtml();





          share|improve this answer

























          • I know that Not what I was looking for! however I've found a solution thanks.

            – Juliano Vargas
            Aug 1 at 11:15











          • please Upvote. If you appreciate.

            – KHIMAJI VALUKIYA
            Aug 1 at 11:18











          • Helpful for others not for me

            – Juliano Vargas
            Aug 1 at 11:19


















          2














          I've found a solution pretty simple.



          $block = $result->getLayout()->setData(['test'=> 'Content here'])->getBlock('category.description');
          $block->setTemplate('Vendor_Module::myTemplate/blank.phtml')
          ->toHtml();


          Then my blank.phtml:



          <?php print_r($this->getData()) ?>


          It prints: Array ( [test] => Content here [module_name] => Magento_Catalog )






          share|improve this answer



























            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%2f284079%2fmagento-2-settemplate-and-add-content-to-phtml-template%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









            3














            You should try this



             echo $this->getLayout()->createBlock("VendorModuleBlockMyblock")- 
            >setTemplate("My_Module::history-suite.phtml")->toHtml();





            share|improve this answer

























            • I know that Not what I was looking for! however I've found a solution thanks.

              – Juliano Vargas
              Aug 1 at 11:15











            • please Upvote. If you appreciate.

              – KHIMAJI VALUKIYA
              Aug 1 at 11:18











            • Helpful for others not for me

              – Juliano Vargas
              Aug 1 at 11:19















            3














            You should try this



             echo $this->getLayout()->createBlock("VendorModuleBlockMyblock")- 
            >setTemplate("My_Module::history-suite.phtml")->toHtml();





            share|improve this answer

























            • I know that Not what I was looking for! however I've found a solution thanks.

              – Juliano Vargas
              Aug 1 at 11:15











            • please Upvote. If you appreciate.

              – KHIMAJI VALUKIYA
              Aug 1 at 11:18











            • Helpful for others not for me

              – Juliano Vargas
              Aug 1 at 11:19













            3












            3








            3







            You should try this



             echo $this->getLayout()->createBlock("VendorModuleBlockMyblock")- 
            >setTemplate("My_Module::history-suite.phtml")->toHtml();





            share|improve this answer













            You should try this



             echo $this->getLayout()->createBlock("VendorModuleBlockMyblock")- 
            >setTemplate("My_Module::history-suite.phtml")->toHtml();






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 1 at 11:13









            KHIMAJI VALUKIYAKHIMAJI VALUKIYA

            415 bronze badges




            415 bronze badges















            • I know that Not what I was looking for! however I've found a solution thanks.

              – Juliano Vargas
              Aug 1 at 11:15











            • please Upvote. If you appreciate.

              – KHIMAJI VALUKIYA
              Aug 1 at 11:18











            • Helpful for others not for me

              – Juliano Vargas
              Aug 1 at 11:19

















            • I know that Not what I was looking for! however I've found a solution thanks.

              – Juliano Vargas
              Aug 1 at 11:15











            • please Upvote. If you appreciate.

              – KHIMAJI VALUKIYA
              Aug 1 at 11:18











            • Helpful for others not for me

              – Juliano Vargas
              Aug 1 at 11:19
















            I know that Not what I was looking for! however I've found a solution thanks.

            – Juliano Vargas
            Aug 1 at 11:15





            I know that Not what I was looking for! however I've found a solution thanks.

            – Juliano Vargas
            Aug 1 at 11:15













            please Upvote. If you appreciate.

            – KHIMAJI VALUKIYA
            Aug 1 at 11:18





            please Upvote. If you appreciate.

            – KHIMAJI VALUKIYA
            Aug 1 at 11:18













            Helpful for others not for me

            – Juliano Vargas
            Aug 1 at 11:19





            Helpful for others not for me

            – Juliano Vargas
            Aug 1 at 11:19













            2














            I've found a solution pretty simple.



            $block = $result->getLayout()->setData(['test'=> 'Content here'])->getBlock('category.description');
            $block->setTemplate('Vendor_Module::myTemplate/blank.phtml')
            ->toHtml();


            Then my blank.phtml:



            <?php print_r($this->getData()) ?>


            It prints: Array ( [test] => Content here [module_name] => Magento_Catalog )






            share|improve this answer





























              2














              I've found a solution pretty simple.



              $block = $result->getLayout()->setData(['test'=> 'Content here'])->getBlock('category.description');
              $block->setTemplate('Vendor_Module::myTemplate/blank.phtml')
              ->toHtml();


              Then my blank.phtml:



              <?php print_r($this->getData()) ?>


              It prints: Array ( [test] => Content here [module_name] => Magento_Catalog )






              share|improve this answer



























                2












                2








                2







                I've found a solution pretty simple.



                $block = $result->getLayout()->setData(['test'=> 'Content here'])->getBlock('category.description');
                $block->setTemplate('Vendor_Module::myTemplate/blank.phtml')
                ->toHtml();


                Then my blank.phtml:



                <?php print_r($this->getData()) ?>


                It prints: Array ( [test] => Content here [module_name] => Magento_Catalog )






                share|improve this answer













                I've found a solution pretty simple.



                $block = $result->getLayout()->setData(['test'=> 'Content here'])->getBlock('category.description');
                $block->setTemplate('Vendor_Module::myTemplate/blank.phtml')
                ->toHtml();


                Then my blank.phtml:



                <?php print_r($this->getData()) ?>


                It prints: Array ( [test] => Content here [module_name] => Magento_Catalog )







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 1 at 11:18









                Juliano VargasJuliano Vargas

                7616 silver badges27 bronze badges




                7616 silver badges27 bronze badges






























                    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%2f284079%2fmagento-2-settemplate-and-add-content-to-phtml-template%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

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?