Templates: How to wrap two blocks inside a container / re-arrange blocks

Hey!

Being more of a web designer and less of a developer, I’m having a hard time wrapping my head around the template structure & manipulation.

I’d like to wrap the “listing_content” and “listing_footer” blocks in the “listing_view_template” but when I re-write the themplate structure in the functions.php in the way it is tought in the videos, I get double the blocks displayed.

What is the correct way to re-arrange the templates or even remove parts of it?
Simply adding the blocks into another blocks seems not to override the original template structure but just adds them.

Is this the correct way of doing it? Is this kind of template structure standardized or where can I learn how to understand and manipulate it?

//-------------------- Wrap View Block Template Parts in Wrapper --------------------
add_filter(
	'hivepress/v1/templates/listing_view_block',
	function( $template ) {
		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'listing_container' => [
						'blocks' => [
							'view_block_wrapper_before' => [
								'order' => 11,
								'type' => 'content',
								'content' => '<div class="jr_view_block_wrapper">',
							],
							'view_block_wrapper_after' => [
								'order' => 31,
								'type' => 'content',
								'content' => '</div>',
							],
						],
					],
				],
			],
		);
	},
	1000
);

Sorry for the confusion, there are new template manipulation functions that are not documented yet. Please use hivepress()->template->merge_blocks($template, $new_blocks) instead of hivepress()->helper->merge_trees($template, $new_blocks) one. If you also use hivepress()->template->fetch_block($template, $block_name) this way you can fetch blocks (get and remove them at the same time) and merge them into any new place or container.

1 Like

Thank you @ihor! Will have a look.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.