how to call phtml inside phtml
.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♦ 13 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♦ 13 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♦ 13 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♦ 13 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