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

                    Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

                    Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form