• Resolved Hans Schuijff

    (@hanswitteprins)


    Hi,

    I’m trying to make a gutenberg block template that uses and prefills the call 2 action block.

    I was able to prefill all settings in that way, and it worked except for the ctaText and perhaps the button size that didn’t respond to values like “large” and probably just need a pixel value.

    Can anyone tell/show how a ctaText value can be passed to the block in a template, so it will show as content in the call 2 action block? Help is greatly appreciated.

    Looking in console the ctaText is an array, but contains objects type ‘p’ and children, when I fill something in the editor. I don’t know how to address that yet in a way that it will work in templates and all my attempts until now have been unsuccessful.

    The code I used to try it out is:

    $wp_post_types['post']->template = array(  
        array( 'genesis-blocks/gb-cta', array( 
            'buttonText'            => 'Some button text',
            'buttonUrl'             => '#respond',
            'buttonAlignment'       => 'center',
            'buttonBackgroundColor' => '#fff',
            'buttonTextColor'       => '#000',
            'buttonSize'            => '32',
            'buttonShape'           => 'round',
            'buttonTarget'          => true,
            'ctaTitle'              => array( 'This is a title' ),
            'titleFontSize'         => 48,
            'ctaText'               => array( 'This is some text' ),
            'ctaTextFontSize'       => 16,
            'ctaWidth'              => '50',
            'ctaBackgroundColor'    => 'red',
            'ctaTextColor'          => '#fff',
        ) ),
        array( 'core/paragraph' ),
    );

    Thanks,

    Hans

Viewing 2 replies - 1 through 2 (of 2 total)
  • @hanswitteprins Thanks for your question! The button size expects a className, for example gb-button-size-medium.

    Trying to point you in the right direction with ctaText – that is used as a the “content” attribute for a RichText control (https://github.com/WordPress/gutenberg/blob/5cd71f42499173e6d6f10a20a4b066f3aab77e34/packages/block-editor/src/components/rich-text/README.md).

    I’ll ask our devs to take a look at this ticket and see if they can provide something more helpful. 🙂

    Thread Starter Hans Schuijff

    (@hanswitteprins)

    Thank you very much, Luke @lukecarbis, for pointing me in the right direction. I was able to manipulate the button now and understand why button size is a string value instead of an integer. 🙂

    I will look further in the workings of RichText controls too and if your devs have some further tips, I will be glad to get more pointers. Perhaps in future the documentation will be more complete for people needing to do such things. It is all still a bit new.

    Luckily I learned on another thread how to insert reusable blocks in a template too, so I will be able to get some progress in my project.

    Thanks,

    Hans

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Prefilling Call to Action block in a block template’ is closed to new replies.