The Orocommerce B2B System manage static block by Content Blocks which are the foundation of your site and they can help create a custom layout. In Oro applications, you can modify the existing content blocks, or create your own. More info and how create manually plz follow this link :
https://oroinc.com/b2b-ecommerce/doc/current/user-guide/marketing-content-blocks
So let’s imagine that you have create one content block , with unique alias ‘home-banner-top’ with any HTML content and restrictions , the question how you can render inside your theme by layout system .
Ok this banner well get showed in the home , the standard route for home page is oro_frontend_root So inside Resources/views/layouts/theme-name add folder oro_frontend_root .
Note: theme-name is your theme name or current default theme like blank.
Now inside folder oro_frontend_root add banner.yml and fill with :
layout: actions: - '@setBlockTheme': themes: 'banner.html.twig' - '@addTree': items: home_banner_top: blockType: content_block prepend: true options: alias: home-banner-top tree: page_content: home_banner_top: ~
What’s means ? Is easy you have added new block which will get related to our content block already created manually from administration ‘home-banner-top’, the type of block is content_block , for more clean and structured YML we use @addTree and placing our new content block directly inside page_content . More info about layout system PLZ refer to our course:
https://www.ibnab.com/en/blog/orocommerce/orocommerce-layouts-system-mvsc or to official docs https://oroinc.com/b2b-ecommerce/doc/current/dev-guide/front-ui/layouts
And we added a file twig which is our renderer file for this block :
- '@setBlockTheme': themes: 'banner.html.twig'
you should add file banner.html.twig inside folder oro_frontend_root and push this code:
{% block _home_banner_top_widget %} {{ block.vars.contentBlock.content | raw }} {% endblock %}
Is easy you’re using the id ‘home_banner_top ‘ of your block to define where you will render this snippet of code and we use {{ block.vars.contentBlock.content }} to render the content of block.
Note: you can dump all variables of this block by using {{ block.vars.contentBlock }} in developer mode
Now you have ability to render you HTML but let’s using other case when you wanna use custom widget inside you content block and render it . Here you should render and compile in same time so your content twig is:
{% block _home_banner_top_widget %} {{ block.vars.contentBlock.content | render_content }} {% endblock %}
the twig function render_content will compile and render you content not just simple raw of html . That is all .
Comments