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;
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
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.
add a comment |
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
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.
add a comment |
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
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
magento2 layout blocks template
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.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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();?>
please let me know if you have any issue
– Rakesh Jesadiya
May 19 '17 at 12:45
add a comment |
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();?>
please let me know if you have any issue
– Rakesh Jesadiya
May 19 '17 at 12:45
add a comment |
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();?>
please let me know if you have any issue
– Rakesh Jesadiya
May 19 '17 at 12:45
add a comment |
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();?>
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();?>
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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