admin管理员组

文章数量:1333427

I have been searching for a day and still carn't seem to find the right documentation for what arguments I can pass to core components when attempting to configure a CPT block template in php. This is what I have but I want to take this further by nesting buttons and custom html etc. but carnt find the docs I need.

'template' => array(
    array( 'core/columns', array(), array(
        array( 'core/column', array("width" => "60"), array(
            array( 'core/image', array() ),
        ) ),
        array( 'core/column', array("width" => "40"), array(
            array( 'core/image', array() ),
            array( 'core/heading', array(
                'placeholder' => 'Add a inner paragraph'
            ) ),
        ) ),
    )
)       

Found everything needed to create bespoke blocks in JSX but blegh, Not got the time to learn the wizardry ways of JSX just yet and I dont really want new blocks just want the existing one bound as a template to a custom post type.

A good way to example my question, how did this person find the answer on how set the width of this template columns.

How to set column widths in a CPT block template?

How did the person find this answer ? did they have to dive in to the JS scripts of the component and work it out or is there some documentation on this or am I missing something all together.

Any help would be greatly appreciated.

I have been searching for a day and still carn't seem to find the right documentation for what arguments I can pass to core components when attempting to configure a CPT block template in php. This is what I have but I want to take this further by nesting buttons and custom html etc. but carnt find the docs I need.

'template' => array(
    array( 'core/columns', array(), array(
        array( 'core/column', array("width" => "60"), array(
            array( 'core/image', array() ),
        ) ),
        array( 'core/column', array("width" => "40"), array(
            array( 'core/image', array() ),
            array( 'core/heading', array(
                'placeholder' => 'Add a inner paragraph'
            ) ),
        ) ),
    )
)       

Found everything needed to create bespoke blocks in JSX but blegh, Not got the time to learn the wizardry ways of JSX just yet and I dont really want new blocks just want the existing one bound as a template to a custom post type.

A good way to example my question, how did this person find the answer on how set the width of this template columns.

How to set column widths in a CPT block template?

How did the person find this answer ? did they have to dive in to the JS scripts of the component and work it out or is there some documentation on this or am I missing something all together.

Any help would be greatly appreciated.

Share Improve this question edited Jun 27, 2020 at 16:33 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jun 27, 2020 at 15:11 JohnnyJohnny 555 bronze badges 1
  • My understanding is that it should take the same format as doing it in JS, then you would directly translate it from JS to PHP in a very literal way, e.g. array() becomes [] ( note that [] is valid in modern PHP versions ) – Tom J Nowell Commented Jun 27, 2020 at 15:18
Add a comment  | 

1 Answer 1

Reset to default 0

You can't find that documentation because it doesn't exist. It doesn't exist because that's not how it works, and it would require extensive duplication to set up.

So to figure out what you need to put, figure out what it is in Javascript/JSON, then translate it to PHP.

The pattern is:

[
    'block name'
    [
        'parameter': 'value'
        .... etc
    ],
    [ .... child blocks ... ]
]

Which brings us to why there is no doc that explicitly mentions these parameters for PHP. Those parameters aren't defined in PHP, they're defined by the blocks themselves, and the blocks are built in javascript. So you won't find a list of parameters for use in PHP block templates, because there isn't one, and it would not make sense to make one. That's not how it works.

So, build your blocks in the block editor, look at their parameters, then write them in in PHP.

A good way to example my question, how did this person find the answer on how set the width of this template columns.

By inspecting the blocks in the editor to see what the parameters of the block were, and what their values were.

本文标签: Where to find documentation for CPT block template (PHP)