Support » Fixing WordPress » Gutenberg Templates plugin?

  • Are there any plugins out there that are good for creating Block Templates?

    Reusable blocks are no good for us because we want to keep using groups of blocks over and over again but each is slightly tweaked each time. With reusable blocks, if you forgot to “convert to blocks” you end up changing all the instances of their use (and it’s an unnecessary extra step) (Unless there is a way of avoiding this with reusable blocks?)

    I’ve created some templates using code and it’s perfect, but it means I have to make them every time we need a new one, rather than just “creating it from the editor”.

    • This topic was modified 2 years, 7 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 9 replies - 1 through 9 (of 9 total)
  • Topher

    (@topher1kenobe)

    I think what you want is Block Patterns, this post will tell you how to make them: https://richtabor.com/build-block-patterns/

    Thread Starter delanthear

    (@delanthear)

    Yes it’s patterns I want to make, that’s what I was meaning when I was referring to templates. Mixing the words up.

    Creating them with code isn’t good enough because we’ll be making quite a few of them routinely and they back up with me to add the code.

    Another option might be to create a pattern as a reusable block:

    https://wordpress.com/support/wordpress-editor/blocks/reusable-block/

    Thread Starter delanthear

    (@delanthear)

    As I said above, reusable blocks don’t work because they are ‘one block’ when used across the site. If you change it, it’s reflected across all the locations unless you convert it back into blocks.

    Unless you know a way to stop this?

    Thread Starter delanthear

    (@delanthear)

    What I need is patterns but being able to create them from the editor. I suspect I’m going to need to make a plugin for it.

    As I said above, reusable blocks don’t work because they are ‘one block’ when used across the site. If you change it, it’s reflected across all the locations unless you convert it back into blocks.

    Ah, sorry I jumped ahead, or behind, or nowhere useful at least, and didn’t realize you needed to tweak them.

    What I need is patterns but being able to create them from the editor. I suspect I’m going to need to make a plugin for it.

    Agree. I don’t think it’d have to be a very large plugin, but it’d help manage a growing library of patterns and ensure consistency.

    https://developer.wordpress.org/block-editor/reference-guides/block-api/block-patterns/#register_block_pattern

    Good luck with it!

    Thread Starter delanthear

    (@delanthear)

    I’m actually building this right now and it seems to work.

    I’ve got some questions though:

    1) It looks like the register_block_pattern() function only works during init. Am I right with that?

    If so, is it appropriate for me to do be doing a db call during every init cycle to grab the published post types I’ve created for them to them to call this function? It feels a bit ugly.

    2) I’m making an assumption that register_block_pattern is something that needs to be called every load for each pattern and that they doesn’t persist. (I.e. I can’t just call it once and the block will stay available forever via some DB entry or something?). Is that right?

    It looks like the register_block_pattern() function only works during init. Am I right with that?

    Yes, that’s what the documentation recommends.

    Though within a custom plugin, I’ve also registered and unregistered patterns in the current_screen and plugins_loaded hooks.

    Sometimes you’ll need $current_screen for example. I can’t say if that’s 100% legit, but it worked for me.

    See also: https://github.com/WordPress/gutenberg/blob/release/11.4/lib/block-patterns.php#L251

    I’m making an assumption that register_block_pattern is something that needs to be called every load for each pattern and that they doesn’t persist.

    I’m pretty sure your assumption is correct here.

    When we register a pattern, they’re loaded every page refresh.

    I think I’m right in saying that we build the patterns registry every time (maybe PHP does some optimisation in the background), and we don’t cache them in transients etc like we do the patterns directory request for example.

    • This reply was modified 2 years, 7 months ago by ramonopoly. Reason: formatting
    Thread Starter delanthear

    (@delanthear)

    Thanks for replying 🙂

    Well, it works now! Adds a custom post type called “Patterns”. When you add one, it appears in the pattern directory. If you give it a category name, it uses that in the patterns dropdown, or defaults to “Custom Patterns”.

    I just need to decide if I can be bothered to tidy it up and submit it! It’s been a long time since I had a plugin published…

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Gutenberg Templates plugin?’ is closed to new replies.