Magento2 : How to add custom block on product page
I want to add my custom template on product page just like $this->getChildHtml('custom_product_info')
.
As in magento1.9 to use $this->getChildHtml('custom_product_info')
we add layout xml like below :
<catalog_product_view>
<reference name="product.info">
<block type="core/template" name="custom_product_info" template="custom.phtml"/>
</reference>
</catalog_product_view>
What is the xml and process to add custom template in Magento2.1?
product magento-2.1.7
add a comment |
I want to add my custom template on product page just like $this->getChildHtml('custom_product_info')
.
As in magento1.9 to use $this->getChildHtml('custom_product_info')
we add layout xml like below :
<catalog_product_view>
<reference name="product.info">
<block type="core/template" name="custom_product_info" template="custom.phtml"/>
</reference>
</catalog_product_view>
What is the xml and process to add custom template in Magento2.1?
product magento-2.1.7
add a comment |
I want to add my custom template on product page just like $this->getChildHtml('custom_product_info')
.
As in magento1.9 to use $this->getChildHtml('custom_product_info')
we add layout xml like below :
<catalog_product_view>
<reference name="product.info">
<block type="core/template" name="custom_product_info" template="custom.phtml"/>
</reference>
</catalog_product_view>
What is the xml and process to add custom template in Magento2.1?
product magento-2.1.7
I want to add my custom template on product page just like $this->getChildHtml('custom_product_info')
.
As in magento1.9 to use $this->getChildHtml('custom_product_info')
we add layout xml like below :
<catalog_product_view>
<reference name="product.info">
<block type="core/template" name="custom_product_info" template="custom.phtml"/>
</reference>
</catalog_product_view>
What is the xml and process to add custom template in Magento2.1?
product magento-2.1.7
product magento-2.1.7
asked Mar 26 '18 at 6:15
Vinaya Maheshwari
1,16211846
1,16211846
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
Try this:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="{Vendor}{Module}BlockCatalogProductView{Class}" name="{your.block.name}" template="{Vendor}_{Module}::{template_name}.phtml">
<!-- If you have any arguments to pass -->
<arguments>
<argument translate="true" name="{argument_name}" xsi:type="string">{Your argument}</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Forclass="{Vendor}{Module}BlockCatalogProductView{Class}"
should I create a block class, please post a example for block class.
– Vinaya Maheshwari
Mar 26 '18 at 6:26
You should be able to use this block:MagentoFrameworkViewElementTemplate
– hungersoft
Mar 26 '18 at 6:27
How can I get$product
in custom template file?
– Vinaya Maheshwari
Mar 26 '18 at 9:28
Follow this tutorial: blog.chapagain.com.np/…
– hungersoft
Mar 26 '18 at 9:30
add a comment |
If you want to add this custom block via Custom module,
Then create catalog_product_view.xml
at app/code/{Vendorname}/{moduleName}/view/frontend/layout
,.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="{Vendor}{Module}Block{BLOCK_CLASSS}" name="{block.name.inlayout}" as="{name_aliase_path}"
template="{Vendor}_{ModuleName}::{YourTemaplte}.phtml">
</block>
</referenceBlock>
</body>
</page>
Then you can call your block via at code at form.phtml at
<?= $block->getChildHtml({name_aliase_path}) ?>
Our custom phtml file will be called as childHtml of any another phtml or we can only call in that particular layout (catalog_product_view.xml
) only which we created our custom phtml file
– inrsaurabh
Mar 26 '18 at 6:59
add a comment |
Use this
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="MagentoFrameworkViewElementTemplate" name="block.name" as="block.alias"
template="{Vendor}_{ModuleName}::{YourTemaplte}.phtml">
</block>
</referenceBlock>
</body>
</page>
add a comment |
<referenceContainer name="product.info.main">
<block class="MagentoFrameworkViewElementTemplate" name="{argument_name}" template="template_name.phtml"/>
</referenceContainer>
add a comment |
<referenceContainer name="content">
<block class="XcommerceCategoryBlockOverview" name="overview"
template="X2commerce_Category::custom.phtml">
</block>
</referenceContainer>
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%2f219813%2fmagento2-how-to-add-custom-block-on-product-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="{Vendor}{Module}BlockCatalogProductView{Class}" name="{your.block.name}" template="{Vendor}_{Module}::{template_name}.phtml">
<!-- If you have any arguments to pass -->
<arguments>
<argument translate="true" name="{argument_name}" xsi:type="string">{Your argument}</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Forclass="{Vendor}{Module}BlockCatalogProductView{Class}"
should I create a block class, please post a example for block class.
– Vinaya Maheshwari
Mar 26 '18 at 6:26
You should be able to use this block:MagentoFrameworkViewElementTemplate
– hungersoft
Mar 26 '18 at 6:27
How can I get$product
in custom template file?
– Vinaya Maheshwari
Mar 26 '18 at 9:28
Follow this tutorial: blog.chapagain.com.np/…
– hungersoft
Mar 26 '18 at 9:30
add a comment |
Try this:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="{Vendor}{Module}BlockCatalogProductView{Class}" name="{your.block.name}" template="{Vendor}_{Module}::{template_name}.phtml">
<!-- If you have any arguments to pass -->
<arguments>
<argument translate="true" name="{argument_name}" xsi:type="string">{Your argument}</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Forclass="{Vendor}{Module}BlockCatalogProductView{Class}"
should I create a block class, please post a example for block class.
– Vinaya Maheshwari
Mar 26 '18 at 6:26
You should be able to use this block:MagentoFrameworkViewElementTemplate
– hungersoft
Mar 26 '18 at 6:27
How can I get$product
in custom template file?
– Vinaya Maheshwari
Mar 26 '18 at 9:28
Follow this tutorial: blog.chapagain.com.np/…
– hungersoft
Mar 26 '18 at 9:30
add a comment |
Try this:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="{Vendor}{Module}BlockCatalogProductView{Class}" name="{your.block.name}" template="{Vendor}_{Module}::{template_name}.phtml">
<!-- If you have any arguments to pass -->
<arguments>
<argument translate="true" name="{argument_name}" xsi:type="string">{Your argument}</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Try this:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="{Vendor}{Module}BlockCatalogProductView{Class}" name="{your.block.name}" template="{Vendor}_{Module}::{template_name}.phtml">
<!-- If you have any arguments to pass -->
<arguments>
<argument translate="true" name="{argument_name}" xsi:type="string">{Your argument}</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
answered Mar 26 '18 at 6:22
hungersoft
2213
2213
Forclass="{Vendor}{Module}BlockCatalogProductView{Class}"
should I create a block class, please post a example for block class.
– Vinaya Maheshwari
Mar 26 '18 at 6:26
You should be able to use this block:MagentoFrameworkViewElementTemplate
– hungersoft
Mar 26 '18 at 6:27
How can I get$product
in custom template file?
– Vinaya Maheshwari
Mar 26 '18 at 9:28
Follow this tutorial: blog.chapagain.com.np/…
– hungersoft
Mar 26 '18 at 9:30
add a comment |
Forclass="{Vendor}{Module}BlockCatalogProductView{Class}"
should I create a block class, please post a example for block class.
– Vinaya Maheshwari
Mar 26 '18 at 6:26
You should be able to use this block:MagentoFrameworkViewElementTemplate
– hungersoft
Mar 26 '18 at 6:27
How can I get$product
in custom template file?
– Vinaya Maheshwari
Mar 26 '18 at 9:28
Follow this tutorial: blog.chapagain.com.np/…
– hungersoft
Mar 26 '18 at 9:30
For
class="{Vendor}{Module}BlockCatalogProductView{Class}"
should I create a block class, please post a example for block class.– Vinaya Maheshwari
Mar 26 '18 at 6:26
For
class="{Vendor}{Module}BlockCatalogProductView{Class}"
should I create a block class, please post a example for block class.– Vinaya Maheshwari
Mar 26 '18 at 6:26
You should be able to use this block:
MagentoFrameworkViewElementTemplate
– hungersoft
Mar 26 '18 at 6:27
You should be able to use this block:
MagentoFrameworkViewElementTemplate
– hungersoft
Mar 26 '18 at 6:27
How can I get
$product
in custom template file?– Vinaya Maheshwari
Mar 26 '18 at 9:28
How can I get
$product
in custom template file?– Vinaya Maheshwari
Mar 26 '18 at 9:28
Follow this tutorial: blog.chapagain.com.np/…
– hungersoft
Mar 26 '18 at 9:30
Follow this tutorial: blog.chapagain.com.np/…
– hungersoft
Mar 26 '18 at 9:30
add a comment |
If you want to add this custom block via Custom module,
Then create catalog_product_view.xml
at app/code/{Vendorname}/{moduleName}/view/frontend/layout
,.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="{Vendor}{Module}Block{BLOCK_CLASSS}" name="{block.name.inlayout}" as="{name_aliase_path}"
template="{Vendor}_{ModuleName}::{YourTemaplte}.phtml">
</block>
</referenceBlock>
</body>
</page>
Then you can call your block via at code at form.phtml at
<?= $block->getChildHtml({name_aliase_path}) ?>
Our custom phtml file will be called as childHtml of any another phtml or we can only call in that particular layout (catalog_product_view.xml
) only which we created our custom phtml file
– inrsaurabh
Mar 26 '18 at 6:59
add a comment |
If you want to add this custom block via Custom module,
Then create catalog_product_view.xml
at app/code/{Vendorname}/{moduleName}/view/frontend/layout
,.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="{Vendor}{Module}Block{BLOCK_CLASSS}" name="{block.name.inlayout}" as="{name_aliase_path}"
template="{Vendor}_{ModuleName}::{YourTemaplte}.phtml">
</block>
</referenceBlock>
</body>
</page>
Then you can call your block via at code at form.phtml at
<?= $block->getChildHtml({name_aliase_path}) ?>
Our custom phtml file will be called as childHtml of any another phtml or we can only call in that particular layout (catalog_product_view.xml
) only which we created our custom phtml file
– inrsaurabh
Mar 26 '18 at 6:59
add a comment |
If you want to add this custom block via Custom module,
Then create catalog_product_view.xml
at app/code/{Vendorname}/{moduleName}/view/frontend/layout
,.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="{Vendor}{Module}Block{BLOCK_CLASSS}" name="{block.name.inlayout}" as="{name_aliase_path}"
template="{Vendor}_{ModuleName}::{YourTemaplte}.phtml">
</block>
</referenceBlock>
</body>
</page>
Then you can call your block via at code at form.phtml at
<?= $block->getChildHtml({name_aliase_path}) ?>
If you want to add this custom block via Custom module,
Then create catalog_product_view.xml
at app/code/{Vendorname}/{moduleName}/view/frontend/layout
,.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="{Vendor}{Module}Block{BLOCK_CLASSS}" name="{block.name.inlayout}" as="{name_aliase_path}"
template="{Vendor}_{ModuleName}::{YourTemaplte}.phtml">
</block>
</referenceBlock>
</body>
</page>
Then you can call your block via at code at form.phtml at
<?= $block->getChildHtml({name_aliase_path}) ?>
edited Mar 26 '18 at 6:33
answered Mar 26 '18 at 6:29
Amit Bera♦
57.2k1374170
57.2k1374170
Our custom phtml file will be called as childHtml of any another phtml or we can only call in that particular layout (catalog_product_view.xml
) only which we created our custom phtml file
– inrsaurabh
Mar 26 '18 at 6:59
add a comment |
Our custom phtml file will be called as childHtml of any another phtml or we can only call in that particular layout (catalog_product_view.xml
) only which we created our custom phtml file
– inrsaurabh
Mar 26 '18 at 6:59
Our custom phtml file will be called as childHtml of any another phtml or we can only call in that particular layout (
catalog_product_view.xml
) only which we created our custom phtml file– inrsaurabh
Mar 26 '18 at 6:59
Our custom phtml file will be called as childHtml of any another phtml or we can only call in that particular layout (
catalog_product_view.xml
) only which we created our custom phtml file– inrsaurabh
Mar 26 '18 at 6:59
add a comment |
Use this
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="MagentoFrameworkViewElementTemplate" name="block.name" as="block.alias"
template="{Vendor}_{ModuleName}::{YourTemaplte}.phtml">
</block>
</referenceBlock>
</body>
</page>
add a comment |
Use this
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="MagentoFrameworkViewElementTemplate" name="block.name" as="block.alias"
template="{Vendor}_{ModuleName}::{YourTemaplte}.phtml">
</block>
</referenceBlock>
</body>
</page>
add a comment |
Use this
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="MagentoFrameworkViewElementTemplate" name="block.name" as="block.alias"
template="{Vendor}_{ModuleName}::{YourTemaplte}.phtml">
</block>
</referenceBlock>
</body>
</page>
Use this
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info">
<block class="MagentoFrameworkViewElementTemplate" name="block.name" as="block.alias"
template="{Vendor}_{ModuleName}::{YourTemaplte}.phtml">
</block>
</referenceBlock>
</body>
</page>
answered Mar 26 '18 at 6:34
Kishan Patadia
3,5201923
3,5201923
add a comment |
add a comment |
<referenceContainer name="product.info.main">
<block class="MagentoFrameworkViewElementTemplate" name="{argument_name}" template="template_name.phtml"/>
</referenceContainer>
add a comment |
<referenceContainer name="product.info.main">
<block class="MagentoFrameworkViewElementTemplate" name="{argument_name}" template="template_name.phtml"/>
</referenceContainer>
add a comment |
<referenceContainer name="product.info.main">
<block class="MagentoFrameworkViewElementTemplate" name="{argument_name}" template="template_name.phtml"/>
</referenceContainer>
<referenceContainer name="product.info.main">
<block class="MagentoFrameworkViewElementTemplate" name="{argument_name}" template="template_name.phtml"/>
</referenceContainer>
answered Mar 26 '18 at 7:19
hweb87
5381723
5381723
add a comment |
add a comment |
<referenceContainer name="content">
<block class="XcommerceCategoryBlockOverview" name="overview"
template="X2commerce_Category::custom.phtml">
</block>
</referenceContainer>
add a comment |
<referenceContainer name="content">
<block class="XcommerceCategoryBlockOverview" name="overview"
template="X2commerce_Category::custom.phtml">
</block>
</referenceContainer>
add a comment |
<referenceContainer name="content">
<block class="XcommerceCategoryBlockOverview" name="overview"
template="X2commerce_Category::custom.phtml">
</block>
</referenceContainer>
<referenceContainer name="content">
<block class="XcommerceCategoryBlockOverview" name="overview"
template="X2commerce_Category::custom.phtml">
</block>
</referenceContainer>
answered yesterday
hitesh balpande
3089
3089
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f219813%2fmagento2-how-to-add-custom-block-on-product-page%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