• How can we set up a block template for specific Page Templates?

    Previously, I have used ACF to extensively customize the available fields and give clients the option to build varying layouts using custom blocks (using the Flexible Content field). These custom blocks have tightly controlled HTML/CSS output so that the look and feel of each page is consistent with the branding and other pages of the site (so the user isn’t able to create off-brand layouts by changing the size of text and layout elements or using off-brand colours, fonts, etc)

    I’ve decided to try and embrace Gutenberg through the use of ACF Blocks. What I have found is I have had to disable many of the default blocks because they provide too much creative control to the user which would result in the aforementioned creation of off-brand layouts/elements, breaking the continuity of the overall site design.

    One thing I’m struggling with is that in the past, I used page templates for certain pages that require custom layouts/template logic and a specific set of custom fields. With ACF, field groups could be assigned to a Page Template and the field group would switch out as soon as you changed the page template. With Gutenberg we don’t seem to able to achieve this as the available blocks don’t swap out when you change the page template.

    I know there is the option to set up “block templates” – but they can only be applied to all posts in a CPT or all pages. I was really excited to learn about this only to be disappointed as I’m not actually able to use this great feature on my current project. What we need is the ability to customize the block template depending on the type of page (ie. the page template). The biggest roadblock I see to this right now is that the user must select the page template and update the page before the new block template would appear. This is far from ideal as most users will probably just jump right into editing the page with the available default blocks.

    Is this something that the Gutenberg team is working on?

Viewing 4 replies - 1 through 4 (of 4 total)
  • I was just about to ask this exact question.

    indithemes

    (@indithemes)

    Any progress on this front?

    bigbritches

    (@bigbritches)

    Also curious what was determined with this, it seems like a CRUCIAL feature that is needed. I’ve just found this JS-based option, but I have no idea as to its viability. I may give it a shot in the coming days – otherwise, I have no path forward to preventing content admins from clobbering specifically-designed page layouts.

    https://webservices.ufhealth.org/2020/07/08/how-to-restrict-blocks-to-specific-page-templates-in-the-wordpress-gutenberg-editor/

    Thread Starter kisabelle

    (@kisabelle)

    Please let me know how it goes with that JavaScript solution! It sounds promising

    I had found a way to restrict the blocks to templates via PHP but the issue was that it wouldn’t load the new restrictions immediately upon changing the page template – it would only do so after you saved the page. It just didn’t seem viable as I felt it had the potential to cause too much confusion so I didn’t even bother to implement it in the end.

    • This reply was modified 4 years ago by kisabelle.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to create block templates for specific Page Templates?’ is closed to new replies.