1

I would like to set a default value for the select on the page layout when creating a new cms page in magento 2. The file I'd like to make an extension for is cms_page_form.xml under module-cms > view > ui_component. Unfortunately <item name="default" xsi:type="string">2</item> to set the second item in the list as default, isn't working. Any thoughts on how to do this in xml?

<field name="page_layout">
        <argument name="data" xsi:type="array">
            <item name="options" xsi:type="object">Magento\Cms\Model\Page\Source\PageLayout</item>
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">text</item>
                <item name="label" xsi:type="string" translate="true">Layout</item>
                <item name="formElement" xsi:type="string">select</item>
                <item name="source" xsi:type="string">page</item>
                <item name="dataScope" xsi:type="string">page_layout</item>
            </item>
        </argument>
    </field>
0

You was very close! you can use the following snippet.

<item name="default" xsi:type="string">Value in select box goes here</item>

And full snippet here

        <field name="page_layout">
        <argument name="data" xsi:type="array">
            <item name="options" xsi:type="object">Magento\Cms\Model\Page\Source\PageLayout</item>
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">text</item>
                <item name="label" xsi:type="string" translate="true">Layout</item>
                <item name="formElement" xsi:type="string">select</item>
                <item name="source" xsi:type="string">page</item>
                <item name="dataScope" xsi:type="string">page_layout</item>
                <item name="default" xsi:type="string">page</item>
            </item>
        </argument>
    </field>

You can find the value of the select box by inspecting it in the browser.

Cheers!

0

1. Create the UI Component XML file

Create [Your_Namespace]/[Your_Module]/view/adminhtml/ui_component/cms_page_form.xml. Add <module name="Magento_Cms"/> to the module's <sequence/> in module.xml.

2. Add the following

Replace [1column] without any layout ID.

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="design">
        <field name="page_layout">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="default" xsi:type="string">[1column]</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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