Page Component

Gets data associated with a block

The Page component calls these methods to see which blocks should be rendered. The Page component calls these methods to get the data that is associated with each block.

ShowroomBlock.tsx
/**
 * Called from WP's block preview screen.
 * Separate from getServerSideProps because private/session based data might need to be mocked.
 * @returns
 */
export const getPreviewProps = async () => {
	return await getPropsData();
};

/**
 * Called by the page the block exists on within it's getServerSideProps method.
 * The result is passed to the component props.
 * @returns
 */
export const getServerSideProps = async () => {
	return await getPropsData();
};

Register Block

gravity-platform-core.php
function gravity_platform_core_blocks_init()
{
	register_block_type(__DIR__ . '/src/blocks/showroom');
  register_block_type(__DIR__ . '/src/blocks/promotions');
}
add_action('init', 'gravity_platform_core_blocks_init');

Add to frontend > components > blocks

[slug] - Detail Page

In [...slug] the post type should be the same as the post type name in the backend.

Last updated

Was this helpful?