By default oro came with many types of blocks the most important two is container and block .
But many cases has a custom behavior for example pass a required variable to your block and using it inside the twig template.
So with Oro layout system you have the ability to create you custom widget based on block So the class parent responsible is Oro\Bundle\LayoutBundle\Layout\Block\Type\ConfigurableType or you can create custom widget based on container by parent oro_layout.block_type.abstract_configurable or oro_layout.block_type.abstract_configurable_container:
oro_layout.block_type.abstract_configurable: abstract: true class: Oro\Bundle\LayoutBundle\Layout\Block\Type\ConfigurableType oro_layout.block_type.abstract_configurable_container: abstract: true parent: oro_layout.block_type.abstract_configurable calls: - [setParent, ['container']]
Let’s start using your custom one firstly to organize the tasks will create block_types.yml inside
Ibnab/Bundle/CustomWidgetBundle/Resources/config/block_types.yml and fill with:
ibnab_custom_widget.layout.type.product: parent: oro_layout.block_type.abstract_configurable calls: - [setOptionsConfig, [{product_id: {}}]] - [setName, ['ibnab_custom_widget_product']]
Here yo have added a custom widget based on block widget which able to accept and option product_id and you can add for example is required
- [setOptionsConfig, [{product_id: {required: true}}]]
So Now how you can using it inside you theme or default blank … or other theme add layout.yml: Ibnab/Bundle/CustomWidgetBundle/Resources/views/layouts/blank/oro_product_frontend_product_view/layout.yml
inside the layout handler oro_product_frontend_product_view (is folder with the route name of product page view which well get dispatched when you’re on product details page) , So you can fill the layout.yml for example with:
layout: actions: - '@setBlockTheme': themes: 'CustomWidgetBundle:layouts:blank/oro_product_frontend_product_view/layout.html.twig' - '@add': id: ibnab_custom_widget_product_direct parentId: product_view_primary_container blockType: ibnab_custom_widget_product prepend: true options: product_id: '=data["product"].getId()'
I think is clear that you have using blockType: ibnab_custom_widget_product with option product_id with =data["product"].getId() (you are in product details page so the product instance is already passed to this handler by custom layout data).
No is the time to create you twig and using you widget and option so add layout.twig and fill with :
{% block _ibnab_custom_widget_product_direct_widget %} {% set attr = layout_attr_defaults(attr, { '~class': ' html' }) %} <div {{ block('block_attributes') }}> Product Id is : {{ product_id}} </div> {% endblock %}
Is a simple example of how you create you custom widget based on block or container abstract service .
For more info PLZ Refer to :
OroCommerce Video for Frontend Developer : Customize product view page
Comments