7

Is it possible to create a matrix block with no fields? I'm using matrix as a page builder and have several scenarios where certain matrix blocks simply act as true/false checks.

As an example, my Horizontal Rule block simply adds an '< hr >' tag to the page. No fieldtype is needed for this block.

I can add a dummy text field to the block that does nothing, but this is not too elegant. Any ideas?

Joe B
  • 146
  • 2

3 Answers3

2

When you create a matrix block type it pre-populates it with a blank field. If you delete this blank field and click save you can have a block with no fields.

patrick.altair
  • 481
  • 3
  • 16
1

I tend to design my matrix block at a slightly higher level. I would have a text block with the rich text editor that allows you to enter a <hr/> tag. You can obviously also use this for all other text on the page, no need for multiple text style blocks.

You would add new block types for rich media components like galleries, videos, widgets, etc.

I know this is not exactly what you are looking for, maybe someone else will have an approach that works for your scenario.

Clark Nelson
  • 679
  • 4
  • 13
  • I'm with you on the higher level blocks... using
    was just an example for the sake of simplicity. The blocks I actually need this for are much more complex. For example, I have a 'Projects' block that if selected would render a grid of cards of all the project entries on the site.
    – Joe B Jun 01 '18 at 15:16
  • Ah I think it's great to use an entries field in that block, then the user is able to set the order of the projects themselves. You could also maybe make a custom field type in a plugin and attach that, potentially preventing the blank matrix block. – Clark Nelson Jun 02 '18 at 15:19
  • 1
    We have used entries fields in for some of our blocks, which works nicely, but in this case we do not want the user to have any control over order. I'm thinking the easiest way might be to simply hide the matrix field and using css. Not an ideal solution, though. – Joe B Jun 04 '18 at 17:08
  • This would be a nice addition, to control content blocks yourself without the requirement of some user input. – Sebastián. Jun 04 '19 at 14:36
1

I've achieved this using this plugin.

It might sound like overkill to use a plugin for something so simple, but I've found this "Entry Instructions" fieldtype to be very handy in a lot of different places too. It supports markdown and css styling, and stands out a bit more than the default instructions.

https://plugins.craftcms.com/entry-instructions

Horizontal rule matrix content builder

Nick
  • 121
  • 3