how to call phtml inside phtml Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Magento 2 Templates: Use `$block` or `$this`?Magento custom block shows Fatal error: Call to a member function setTemplate() on a non-objectMagento 1.8 - Display block in email templateMagento 2: How to call custom phtml file in another phtml file?Magento 2 : Fatal error: Uncaught Error: Call to a member function dispatch() | Store InformationCreate custom block inside headerHow to call widget with products of specific category in “.phtml” file?How to call widget with products of specific category in “.phtml” file?call other layout and block in custom phtmlHow to use session and pass some value to phtml file to phtml file?Magento2: How to call custom block in phtml file

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

Amount of permutations on an NxNxN Rubik's Cube

Crossing US/Canada Border for less than 24 hours

Do wooden building fires get hotter than 600°C?

What does it mean that physics no longer uses mechanical models to describe phenomena?

Trademark violation for app?

Using audio cues to encourage good posture

Question about debouncing - delay of state change

Can a new player join a group only when a new campaign starts?

Why aren't air breathing engines used as small first stages?

How would a mousetrap for use in space work?

Effects on objects due to a brief relocation of massive amounts of mass

How to install press fit bottom bracket into new frame

What initially awakened the Balrog?

How could we fake a moon landing now?

Illegal assignment from sObject to Id

What was the first language to use conditional keywords?

What is a fractional matching?

The code below, is it ill-formed NDR or is it well formed?

Converted a Scalar function to a TVF function for parallel execution-Still running in Serial mode

An adverb for when you're not exaggerating

Most bit efficient text communication method?

What is the appropriate index architecture when forced to implement IsDeleted (soft deletes)?

Significance of Cersei's obsession with elephants?



how to call phtml inside phtml



Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Magento 2 Templates: Use `$block` or `$this`?Magento custom block shows Fatal error: Call to a member function setTemplate() on a non-objectMagento 1.8 - Display block in email templateMagento 2: How to call custom phtml file in another phtml file?Magento 2 : Fatal error: Uncaught Error: Call to a member function dispatch() | Store InformationCreate custom block inside headerHow to call widget with products of specific category in “.phtml” file?How to call widget with products of specific category in “.phtml” file?call other layout and block in custom phtmlHow to use session and pass some value to phtml file to phtml file?Magento2: How to call custom block in phtml file



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








1















I have a custom phtml inside I called attribute.phtml but it's not working:



echo $block->getTemplateFile('Magento_Catalog::product/view/attribute.phtml');
echo $this->getLayout()
->createBlock("MagentoFrameworkViewElementTemplate")
->setTemplate("Magento_Catalog::product/view/attribute.phtml")
->toHtml();


Both showing error only.










share|improve this question
















bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.





















    1















    I have a custom phtml inside I called attribute.phtml but it's not working:



    echo $block->getTemplateFile('Magento_Catalog::product/view/attribute.phtml');
    echo $this->getLayout()
    ->createBlock("MagentoFrameworkViewElementTemplate")
    ->setTemplate("Magento_Catalog::product/view/attribute.phtml")
    ->toHtml();


    Both showing error only.










    share|improve this question
















    bumped to the homepage by Community 5 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















      1












      1








      1


      1






      I have a custom phtml inside I called attribute.phtml but it's not working:



      echo $block->getTemplateFile('Magento_Catalog::product/view/attribute.phtml');
      echo $this->getLayout()
      ->createBlock("MagentoFrameworkViewElementTemplate")
      ->setTemplate("Magento_Catalog::product/view/attribute.phtml")
      ->toHtml();


      Both showing error only.










      share|improve this question
















      I have a custom phtml inside I called attribute.phtml but it's not working:



      echo $block->getTemplateFile('Magento_Catalog::product/view/attribute.phtml');
      echo $this->getLayout()
      ->createBlock("MagentoFrameworkViewElementTemplate")
      ->setTemplate("Magento_Catalog::product/view/attribute.phtml")
      ->toHtml();


      Both showing error only.







      magento2 layout blocks template






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 19 '17 at 11:33









      Siarhey Uchukhlebau

      10.1k93058




      10.1k93058










      asked May 19 '17 at 11:05









      Magento 2Magento 2

      2,41172877




      2,41172877





      bumped to the homepage by Community 5 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 5 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Pass Block file as, MagentoCatalogBlockProductViewDescription
          Just keep below line in your phtml file,



          <?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductViewDescription")->setTemplate("Magento_Catalog::product/view/attribute.phtml")->toHtml();?>





          share|improve this answer























          • please let me know if you have any issue

            – Rakesh Jesadiya
            May 19 '17 at 12:45


















          0














          If you want use the Magento_Catalog::product/view/attribute.phtml you should add important data to the block before layout render it (from the template):



          $_product = $block->getProduct();
          $_call = $block->getAtCall();
          $_code = $block->getAtCode();
          $_className = $block->getCssClass();
          $_attributeLabel = $block->getAtLabel();
          $_attributeType = $block->getAtType();
          $_attributeAddAttribute = $block->getAddAttribute();


          So according to your needs you can pass block arguments to the createBlock method using third argument:



          /**
          * Block Factory
          *
          * @param string $type
          * @param string $name
          * @param array $arguments
          * @return ElementBlockInterface
          */
          public function createBlock($type, $name = '', array $arguments = []);


          Your code should looks like this (I use the SKU-attribute as an example):



          $block->getLayout()
          ->createBlock(
          'MagentoFrameworkViewElementTemplate',
          '',
          [
          "at_call" => 'getSku',
          "at_code" => 'sku',
          "css_class" => 'sku',
          "at_label" => 'default',
          "add_attribute" => 'itemprop="sku"',
          "product" => $block->getProduct() // Here should be real current product, you should load it in your main block!
          ])
          ->setTemplate("Magento_Catalog::product/view/attribute.phtml")
          ->toHtml();


          PS: Try to change $this to the $block in your code:



          <?php echo ($block->getTemplateFile('Magento_Catalog::product/view/attribute.phtml')) ;?>
          <?php echo $block->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("Magento_Catalog::product/view/attribute.phtml")->toHtml();?>


          In Magento 2 you should use the $block variable inside a template, not $this. Here you can find additional info.






          share|improve this answer

























          • After addin this it break the site

            – Magento 2
            May 19 '17 at 11:10











          • @Kothari see updated answer. Please, add error from the log to your question.

            – Siarhey Uchukhlebau
            May 19 '17 at 11:14











          • @Kothari still have same issues?

            – Siarhey Uchukhlebau
            May 30 '17 at 8:55











          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%2f175255%2fhow-to-call-phtml-inside-phtml%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









          0














          Pass Block file as, MagentoCatalogBlockProductViewDescription
          Just keep below line in your phtml file,



          <?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductViewDescription")->setTemplate("Magento_Catalog::product/view/attribute.phtml")->toHtml();?>





          share|improve this answer























          • please let me know if you have any issue

            – Rakesh Jesadiya
            May 19 '17 at 12:45















          0














          Pass Block file as, MagentoCatalogBlockProductViewDescription
          Just keep below line in your phtml file,



          <?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductViewDescription")->setTemplate("Magento_Catalog::product/view/attribute.phtml")->toHtml();?>





          share|improve this answer























          • please let me know if you have any issue

            – Rakesh Jesadiya
            May 19 '17 at 12:45













          0












          0








          0







          Pass Block file as, MagentoCatalogBlockProductViewDescription
          Just keep below line in your phtml file,



          <?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductViewDescription")->setTemplate("Magento_Catalog::product/view/attribute.phtml")->toHtml();?>





          share|improve this answer













          Pass Block file as, MagentoCatalogBlockProductViewDescription
          Just keep below line in your phtml file,



          <?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductViewDescription")->setTemplate("Magento_Catalog::product/view/attribute.phtml")->toHtml();?>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 19 '17 at 11:11









          Rakesh JesadiyaRakesh Jesadiya

          30.4k1577125




          30.4k1577125












          • please let me know if you have any issue

            – Rakesh Jesadiya
            May 19 '17 at 12:45

















          • please let me know if you have any issue

            – Rakesh Jesadiya
            May 19 '17 at 12:45
















          please let me know if you have any issue

          – Rakesh Jesadiya
          May 19 '17 at 12:45





          please let me know if you have any issue

          – Rakesh Jesadiya
          May 19 '17 at 12:45













          0














          If you want use the Magento_Catalog::product/view/attribute.phtml you should add important data to the block before layout render it (from the template):



          $_product = $block->getProduct();
          $_call = $block->getAtCall();
          $_code = $block->getAtCode();
          $_className = $block->getCssClass();
          $_attributeLabel = $block->getAtLabel();
          $_attributeType = $block->getAtType();
          $_attributeAddAttribute = $block->getAddAttribute();


          So according to your needs you can pass block arguments to the createBlock method using third argument:



          /**
          * Block Factory
          *
          * @param string $type
          * @param string $name
          * @param array $arguments
          * @return ElementBlockInterface
          */
          public function createBlock($type, $name = '', array $arguments = []);


          Your code should looks like this (I use the SKU-attribute as an example):



          $block->getLayout()
          ->createBlock(
          'MagentoFrameworkViewElementTemplate',
          '',
          [
          "at_call" => 'getSku',
          "at_code" => 'sku',
          "css_class" => 'sku',
          "at_label" => 'default',
          "add_attribute" => 'itemprop="sku"',
          "product" => $block->getProduct() // Here should be real current product, you should load it in your main block!
          ])
          ->setTemplate("Magento_Catalog::product/view/attribute.phtml")
          ->toHtml();


          PS: Try to change $this to the $block in your code:



          <?php echo ($block->getTemplateFile('Magento_Catalog::product/view/attribute.phtml')) ;?>
          <?php echo $block->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("Magento_Catalog::product/view/attribute.phtml")->toHtml();?>


          In Magento 2 you should use the $block variable inside a template, not $this. Here you can find additional info.






          share|improve this answer

























          • After addin this it break the site

            – Magento 2
            May 19 '17 at 11:10











          • @Kothari see updated answer. Please, add error from the log to your question.

            – Siarhey Uchukhlebau
            May 19 '17 at 11:14











          • @Kothari still have same issues?

            – Siarhey Uchukhlebau
            May 30 '17 at 8:55















          0














          If you want use the Magento_Catalog::product/view/attribute.phtml you should add important data to the block before layout render it (from the template):



          $_product = $block->getProduct();
          $_call = $block->getAtCall();
          $_code = $block->getAtCode();
          $_className = $block->getCssClass();
          $_attributeLabel = $block->getAtLabel();
          $_attributeType = $block->getAtType();
          $_attributeAddAttribute = $block->getAddAttribute();


          So according to your needs you can pass block arguments to the createBlock method using third argument:



          /**
          * Block Factory
          *
          * @param string $type
          * @param string $name
          * @param array $arguments
          * @return ElementBlockInterface
          */
          public function createBlock($type, $name = '', array $arguments = []);


          Your code should looks like this (I use the SKU-attribute as an example):



          $block->getLayout()
          ->createBlock(
          'MagentoFrameworkViewElementTemplate',
          '',
          [
          "at_call" => 'getSku',
          "at_code" => 'sku',
          "css_class" => 'sku',
          "at_label" => 'default',
          "add_attribute" => 'itemprop="sku"',
          "product" => $block->getProduct() // Here should be real current product, you should load it in your main block!
          ])
          ->setTemplate("Magento_Catalog::product/view/attribute.phtml")
          ->toHtml();


          PS: Try to change $this to the $block in your code:



          <?php echo ($block->getTemplateFile('Magento_Catalog::product/view/attribute.phtml')) ;?>
          <?php echo $block->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("Magento_Catalog::product/view/attribute.phtml")->toHtml();?>


          In Magento 2 you should use the $block variable inside a template, not $this. Here you can find additional info.






          share|improve this answer

























          • After addin this it break the site

            – Magento 2
            May 19 '17 at 11:10











          • @Kothari see updated answer. Please, add error from the log to your question.

            – Siarhey Uchukhlebau
            May 19 '17 at 11:14











          • @Kothari still have same issues?

            – Siarhey Uchukhlebau
            May 30 '17 at 8:55













          0












          0








          0







          If you want use the Magento_Catalog::product/view/attribute.phtml you should add important data to the block before layout render it (from the template):



          $_product = $block->getProduct();
          $_call = $block->getAtCall();
          $_code = $block->getAtCode();
          $_className = $block->getCssClass();
          $_attributeLabel = $block->getAtLabel();
          $_attributeType = $block->getAtType();
          $_attributeAddAttribute = $block->getAddAttribute();


          So according to your needs you can pass block arguments to the createBlock method using third argument:



          /**
          * Block Factory
          *
          * @param string $type
          * @param string $name
          * @param array $arguments
          * @return ElementBlockInterface
          */
          public function createBlock($type, $name = '', array $arguments = []);


          Your code should looks like this (I use the SKU-attribute as an example):



          $block->getLayout()
          ->createBlock(
          'MagentoFrameworkViewElementTemplate',
          '',
          [
          "at_call" => 'getSku',
          "at_code" => 'sku',
          "css_class" => 'sku',
          "at_label" => 'default',
          "add_attribute" => 'itemprop="sku"',
          "product" => $block->getProduct() // Here should be real current product, you should load it in your main block!
          ])
          ->setTemplate("Magento_Catalog::product/view/attribute.phtml")
          ->toHtml();


          PS: Try to change $this to the $block in your code:



          <?php echo ($block->getTemplateFile('Magento_Catalog::product/view/attribute.phtml')) ;?>
          <?php echo $block->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("Magento_Catalog::product/view/attribute.phtml")->toHtml();?>


          In Magento 2 you should use the $block variable inside a template, not $this. Here you can find additional info.






          share|improve this answer















          If you want use the Magento_Catalog::product/view/attribute.phtml you should add important data to the block before layout render it (from the template):



          $_product = $block->getProduct();
          $_call = $block->getAtCall();
          $_code = $block->getAtCode();
          $_className = $block->getCssClass();
          $_attributeLabel = $block->getAtLabel();
          $_attributeType = $block->getAtType();
          $_attributeAddAttribute = $block->getAddAttribute();


          So according to your needs you can pass block arguments to the createBlock method using third argument:



          /**
          * Block Factory
          *
          * @param string $type
          * @param string $name
          * @param array $arguments
          * @return ElementBlockInterface
          */
          public function createBlock($type, $name = '', array $arguments = []);


          Your code should looks like this (I use the SKU-attribute as an example):



          $block->getLayout()
          ->createBlock(
          'MagentoFrameworkViewElementTemplate',
          '',
          [
          "at_call" => 'getSku',
          "at_code" => 'sku',
          "css_class" => 'sku',
          "at_label" => 'default',
          "add_attribute" => 'itemprop="sku"',
          "product" => $block->getProduct() // Here should be real current product, you should load it in your main block!
          ])
          ->setTemplate("Magento_Catalog::product/view/attribute.phtml")
          ->toHtml();


          PS: Try to change $this to the $block in your code:



          <?php echo ($block->getTemplateFile('Magento_Catalog::product/view/attribute.phtml')) ;?>
          <?php echo $block->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("Magento_Catalog::product/view/attribute.phtml")->toHtml();?>


          In Magento 2 you should use the $block variable inside a template, not $this. Here you can find additional info.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 19 '17 at 11:26

























          answered May 19 '17 at 11:08









          Siarhey UchukhlebauSiarhey Uchukhlebau

          10.1k93058




          10.1k93058












          • After addin this it break the site

            – Magento 2
            May 19 '17 at 11:10











          • @Kothari see updated answer. Please, add error from the log to your question.

            – Siarhey Uchukhlebau
            May 19 '17 at 11:14











          • @Kothari still have same issues?

            – Siarhey Uchukhlebau
            May 30 '17 at 8:55

















          • After addin this it break the site

            – Magento 2
            May 19 '17 at 11:10











          • @Kothari see updated answer. Please, add error from the log to your question.

            – Siarhey Uchukhlebau
            May 19 '17 at 11:14











          • @Kothari still have same issues?

            – Siarhey Uchukhlebau
            May 30 '17 at 8:55
















          After addin this it break the site

          – Magento 2
          May 19 '17 at 11:10





          After addin this it break the site

          – Magento 2
          May 19 '17 at 11:10













          @Kothari see updated answer. Please, add error from the log to your question.

          – Siarhey Uchukhlebau
          May 19 '17 at 11:14





          @Kothari see updated answer. Please, add error from the log to your question.

          – Siarhey Uchukhlebau
          May 19 '17 at 11:14













          @Kothari still have same issues?

          – Siarhey Uchukhlebau
          May 30 '17 at 8:55





          @Kothari still have same issues?

          – Siarhey Uchukhlebau
          May 30 '17 at 8:55

















          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%2f175255%2fhow-to-call-phtml-inside-phtml%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

          Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

          How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2

          Nissan Patrol Зміст Перше покоління — 4W60 (1951-1960) | Друге покоління — 60 series (1960-1980) | Третє покоління (1980–2002) | Четверте покоління — Y60 (1987–1998) | П'яте покоління — Y61 (1997–2013) | Шосте покоління — Y62 (2010- ) | Посилання | Зноски | Навігаційне менюОфіційний український сайтТест-драйв Nissan Patrol 2010 7-го поколінняNissan PatrolКак мы тестировали Nissan Patrol 2016рвиправивши або дописавши її