Magento Expert Forum - Improve your Magento experience

Results 1 to 2 of 2

How To Create Magento 2 Blocks With Blocks Builder

  1. #1
    Junior Member
    Join Date
    Apr 2016
    Posts
    382
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How To Create Magento 2 Blocks With Blocks Builder

    How To Create Magento 2 Blocks With Blocks Builder

    View more Magento 2 Themes

    Name:  10-Best-Highly-Advanced-extension.jpg
Views: 15
Size:  328.9 KB

    In this post, we will show you how to create magento 2 blocks in 2 ways. The first one is to write code to test out functionality.
    The second one is to use magento 2 blocks builder. This tool is included in Magento 2 Page Builder extension. Learn more here.

    I. How To Create Magento 2 Blocks by writing code

    Name:  helloworld_structure.png
Views: 14
Size:  16.0 KB

    1. Create a module.xml in in app/code/Lof/HelloWorld/etc

    PHP Code:
    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
        <module name="Lof_HelloWorld" setup_version="1.0.0">
        </module>
    </config>
    2. Create app/code/Lof/HelloWorld/registration.php file

    PHP Code:
    <?php
    MagentoFrameworkComponentComponentRegistrar
    ::register(
        
    MagentoFrameworkComponentComponentRegistrar::MODULE,
        
    'Lof_HelloWorld',
        
    __DIR__
        
    );
    3. Create a layout file in the following directory appcodeLofHelloWorldViewfrontendlayoutcms_index_in dex.xml

    The cms_index_index.xml name will make our block only appear on the home page (module_controller_action.xml).

    PHP Code:
    <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
        <body>
            <referenceContainer name="content">
                <block class="LofHelloWorldBlockHelloWorld" before='-' template="helloworld.phtml"/>
            </referenceContainer>
        </body>
    </page>
    4. Lets create a block for our module. Create block file app/code/Lof/HelloWorld/Block/HelloWorld.php

    PHP Code:
    <?php
    namespace LofHelloWorldBlock;
     
    /**
    * Helloworld Block
    */
    class Helloworld extends MagentoFrameworkViewElementTemplate
    {
        public function 
    getTitle()
        {
            return 
    __("LOF Hello World");
        }
    }
    5. Create a template file app/code/Lof/HelloWorld/View/frontend/templates/helloworld.phtml

    6. Active Lof_HelloWorld extension

    We have two ways to active Lof_Helloworld extension

    1) Open Command line in folder root of magento and run commands:
    php bin/magento setup:upgrade


    Name:  helloworld_commandline.png
Views: 14
Size:  67.0 KB

    2) Directly edit file app/etc/config.xml: In the array module, add the element: ‘Lof_Helloworld’ => 1

    Name:  helloworld_config.png
Views: 14
Size:  55.5 KB

    7. Run the command line refresh cache and check home page
    php bin/magento cache:flush


    Name:  helloworld_ui.png
Views: 14
Size:  229.1 KB

    II. How to create block with block builder.

    Ves Block Builder is one of amazing tool that let you to build any type of blocks with ease. This tool included in Magento 2 Page Builder extension. Learn more here:

    1. Add block profile

    Please go to Admin panel >> Ves page builder >> Add new block profile



    2. Design your block

    Then, you need to open “design” tab to start designing your own block



    – Prefix class: This class is to custom
    – Enable container: If you want to enable container, you can select yes and vice versa
    – Use backup layout: You can take use of backup layout from select box
    – Design in: This funtions lets you create responsive blocks on lagre screen, laptop, tablets, mobile.

    – Enable Grid: you can enable/disable grid



    3. Manage blocks



    VIEW DETAIL->

    View more threads in the same category:


  2. #2
    Junior Member
    Join Date
    Nov 2019
    Posts
    1,083
    Thanks
    6
    Thanked 3 Times in 3 Posts

    Default

    This is really a very wonderful post. Thanks for sharing.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •