2

I have little Confused about page_types.xml. Why we need this? and How this Useful for us? I researched about page_types.xml in this document Still not get exact answer.

I saw some page_types in magento Calalog_module:

<page_types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_types.xsd">
    <type id="catalog_category_view" label="Catalog Category"/>
    <type id="catalog_product_compare_index" label="Catalog Product Compare List"/>
    <type id="catalog_product_gallery" label="Catalog Product Image Gallery Popup"/>
    <type id="catalog_product_view" label="Catalog Product View (Any)"/>
</page_types>

I dont know, where to use this types.

Suggest me Why we need this? and How to Usefull for us?

1
  • 1
    Need some input on this. please help us to clear this
    – Shivam
    Commented Apr 26, 2018 at 13:45

1 Answer 1

2

Magento define each page have it own type. You can see how it implement in admin widget inside Content > Widget. This module allow you add widget block to any where in your page. If you want add to your specific place. Create your own page type and layout and add it to there.

Magento\Framework\View\Layout\PageType\Config::getPageTypes()

    /**
     * Retrieve available page types
     *
     * @return \Magento\Framework\DataObject[]
     */
    public function getPageTypes()
    {
        $this->_initPageTypes();
        return $this->_pageTypes;
    }

Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\Layout

/**
     * Add necessary options
     *
     * @return \Magento\Framework\View\Element\AbstractBlock
     */
    protected function _beforeToHtml()
    {
        if (!$this->getOptions()) {
            $this->addOption('', __('-- Please Select --'));
            $pageTypes = $this->_config->getPageTypes();
            $this->_addPageTypeOptions($pageTypes);
        }
        return parent::_beforeToHtml();
    }

That mean you can create your own page with own page type and ability add to layout handle you want

Example: create your own define page type: /etc/frontend/example_page_types.xml

<example_page_types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_types.xsd">
    <type id="your-route_action_index" label="Your custom Pages"/>
</example_page_types>

type id is corresponding to layout handle define your page when controller call

1
  • page have it own type? I am not clear with this. Can you please help me to understand.
    – Shivam
    Commented Apr 26, 2018 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.