• Resolved Gyurmey

    (@gyurmey)


    Hi,

    How do I add a block variation for a specific part of the template? I’m trying to add a sticky header variation, but it’s showing up in every part of the template. Here is sample code:

    wp.blocks.registerBlockVariation('core/template-part', [
    	{
    		name: 'sticky-header',
    		title: __('Sticky Header'),
    		attributes: {
    			area: 'header',
    			className: 'site-header is-sticky',
    		},
    		scope: ['transform'],
    	},
    	{
    		name: 'static-header',
    		title: __('Static Header'),
    		attributes: {
    			area: 'header',
    			className: 'site-header is-static',
    		},
    		scope: ['transform'],
    	},
    ]);
    

    Any ideas? Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @gyurmey, thanks for reaching out.

    In my testing, it does not appear that variations are supported for different template part “areas”. Setting the attribute area: 'header' does not actually do anything, which is why you are seeing the variations show up on each template part.

    I have opened a ticket on GitHub for the team to consider adding this functionality. Interestingly enough, you can define semantic patterns based on template part areas.

    For example, the following code will define a pattern specifically for header template parts.

    register_block_pattern(
        'example-theme/semantic-pattern',
        array(
            'title'      => __( 'A semantic pattern for header template parts.', 'example-theme' ),
            'blockTypes' => array( 'core/template-part/header' ),
            'content'    => '<!-- Insert Pattern Content -->',
        )
    );

    You can read more about semantic patterns in a recent article I wrote.

    Please let me know if I can provide further assistance.

    Best,
    Nick

    Thread Starter Gyurmey

    (@gyurmey)

    @ndiego, Thank you for your efforts. I will be watching the issue.

    Thank you for chiming in @ndiego ?? I will mark this thread as resolved for now.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Register block variation for specific template part’ is closed to new replies.