how should I create a custom layout file , custom container and add custom blocks to containers? I dont know where to place which one. can anybody give an example of adding a block that says "hello" to the container using custom layout I am new to magento. I am learning! please help
<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framewrk:View/Layout/etc/page_layout.xsd">
<update handle="empty"/>
<referenceContainer name="page.wrapper">
<container name="header.container" as="header.container" label="Pag Header Container" htmlTag="header" htmlClass="page-header" before="main.content"/>
<container name="page.top" as="page_top" label="After Page Header" after="header.container"/>
<container name="footer-container" as="footer" before="before.body.end" label="Page Footer Container" htmlTag="footer" htmlClass="page-footer" />
</referenceContainer>
</layout>
I created a E:\xampp\htdocs\magento-2\app\design\frontend\vendor\my_new_theme\Magento_Theme\page-layout\test-layout.xml and registered in E:\xampp\htdocs\magento-2\app\design\frontend\vendor\my_new_theme\Magento_Theme\layouts.xml where should my blocks go?
-
You can have look at official documentation. Things are explained well there. Go for example: devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/…, devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/…Jarnail S– Jarnail S2017年06月27日 04:12:33 +00:00Commented Jun 27, 2017 at 4:12
-
Its bit confusing @Jailearner– learner2017年06月27日 04:45:46 +00:00Commented Jun 27, 2017 at 4:45
-
Follow this link webkul.com/blog/create-hello-module-in-magento2.. I have learnt from the website and follow each and every step. It works well.Pavan Kumar– Pavan Kumar2017年06月27日 04:52:44 +00:00Commented Jun 27, 2017 at 4:52
-
Check @Manoj's answer. Comment below if you have any confusion. We will clear thatJarnail S– Jarnail S2017年06月27日 05:11:14 +00:00Commented Jun 27, 2017 at 5:11
1 Answer 1
After adding your custom theme , you can place your custom code in default.xml
/app/design/frontend/yourvendor/yourtheme/Magento_Theme/layout/default.xml
For Custom container: <container name="test.container" as="testContainer" label="test Container" htmlTag="div" htmlClass="test-container" />
For adding/removing something from test container use referenceContainer :
For example you have some content says " hello" in hello-block.html placed in Magento_Theme module then call the file in your custom container.
<referenceContainer name="test.container">
<block class="Magento\Framework\View\Element\Template" name="hello-block" template="Magento_Theme::hello-block.phtml"/></referenceContainer>
For removing something , for ex Remove whishlist:
<referenceContainer name="wishlist_sidebar" remove="true" />
For adding content through admin block and then calling block in html file use
{{block class="Magento\\Cms\\Block\\Block" block_id="hello-block"}}</div>
For calling static resources , your custom css and js adding bootstrap, call files in default_head_blocks.xml
app/design/frontend/yourvendor/yourtheme/Magento_Theme/layout/default_head_blocks.xml
<css src="css/bootstrap.css" />
<script src="js/bootstrap.js"></script>
Place both files under /app/design/frontend/yourvendor/yourtheme/web/css or js
Remove existing css and js
<remove src="css/styles-m.css" />
I hope these things will help you to some extent
-
Its working..!! what is the class attribute in block?learner– learner2017年06月27日 08:33:49 +00:00Commented Jun 27, 2017 at 8:33
-
class attribute implements rendering of a particular block. Basically take care of actual rendering of block out put. for more details on each attribute of block ,checkout this ... devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/…Manoj Deswal– Manoj Deswal2017年06月27日 09:14:22 +00:00Commented Jun 27, 2017 at 9:14