• Resolved notknow

    (@notknow)


    Hello.

    I have read the other posts on this topic thoroughly but i cannot get my head around what i need where, sorry to ask again but i am really, really stuck:

    I have this in my functions.php:

    	function my_block_editor_assets() {
    		wp_enqueue_script(
    			'my-block-editor-js',
    			get_stylesheet_directory_uri() . './block-editor/block-filter.js',
    			array( 'wp-hooks' ),
    			'1.0.0',
    			true // Enqueue the script in the footer.
    		);
    	}
    	add_action( 'enqueue_block_editor_assets', 'my_block_editor_assets' );

    The file ‘block-filter.js’ resides in ‘themename/block-editor/block-filter.js’ (so the folder ‘block-editor’ and my functions.php are on the same level).

    The content of this file is:

    function myRowTemplates(templates) {
    
    		templates.push( {
    
    			name: '1-1-1-1',
    			title: '4 Columns',
    			icon: 'layout',
    			templateLock: 'all',
    			template: [
    
    				[
    					'wp-bootstrap-blocks/column',
    					{
    						sizeLg: 3,
    						sizeMd: 6
    					}
    				],
    				[
    					'wp-bootstrap-blocks/column',
    					{
    						sizeLg: 3,
    						sizeMd: 6
    					}
    				],
    				[
    					'wp-bootstrap-blocks/column',
    					{
    						sizeLg: 3,
    						sizeMd: 6
    					}
    				],
    				[
    					'wp-bootstrap-blocks/column',
    					{
    						sizeLg: 3,
    						sizeMd: 6
    					}
    				]
    			]
    		});
    
    		return templates;
    	}
    
    	wp.hooks.addFilter('wpBootstrapBlocks.row.templates', 'themename/wp-bootstrap-blocks/row/templates', myRowTemplates);

    Do i need anything else?
    Somehow it seems i also need a file in ‘themename/wp-bootstrap-blocks/row/template’ so i tried to copy the file from the extension into that place, so in there i have the file ‘row.php’ with its original content.

    I am completely stuck, like sitting in front of a wall i’d like to look through but can not.

    Any help is definitely welcome and appreciated.
    Will try to get along but please, if you have an idea what i’m missing, please tell me ??

    Thank you so much, cheers, Frank

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter notknow

    (@notknow)

    Hm,

    i had an error left in this line because of earlier tests with pathoptions:
    get_stylesheet_directory_uri() . './block-editor/block-filter.js',

    One dot too much, that was:
    get_stylesheet_directory_uri() . '/block-editor/block-filter.js',

    I can see the option now in the toolbar, it creates 4 columns in the backend.

    Super nice.
    Will now try and remove that row template and see if it still works.

    • This reply was modified 4 years, 4 months ago by notknow.
    Thread Starter notknow

    (@notknow)

    I deleted the whole folder ‘themename/wp-bootstrap-blocks’.

    So, inside of ‘block-filters.js’ i still have the line

    wp.hooks.addFilter('wpBootstrapBlocks.row.templates', 'themename/wp-bootstrap-blocks/row/templates', myRowTemplates);

    but there is no such folder ”themename/wp-bootstrap-blocks/row/templates’ anymore and there is no such file ‘row.php’ anymore (but the default one from the original extension folder).

    So, *why* is this *still working* (i have my 4-columns-option there and it works, but, yes, why) ??

    Please, somebody, help me to not stay clueless, thank you.

    Plugin Contributor tschortsch

    (@tschortsch)

    Hi @notknow. Your custom template definition looks good. You don’t need to overwrite the row.php template for this to work. A custom row template just defines a pre-configuration of the inner column blocks. It isn’t adding any more functionality which would require to overwrite the row.php template.

    Thread Starter notknow

    (@notknow)

    Ah, thank you for your reply.
    So you have some kind of relpacement hierarchy, like with templates, *if* a custom file exists you use that one, if not you use your shipped version. It’s often exactly these things that deliver some extra information that is interesting.
    Thanks you for answering and thanks por the plugin.

    Plugin Contributor tschortsch

    (@tschortsch)

    Exactly, the plugin provides a default template for each block (you can have look at them here: https://github.com/liip/bootstrap-blocks-wordpress-plugin/tree/master/src/templates). As soon as one of these templates is found in the wp-bootstrap-blocks folder inside of your WP template folder this file is used instead of the default one. This can be used to modify the output of each block to your own needs.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom row template, again’ is closed to new replies.