1

we have a problem over and over again and I wonder if we're missing something. Using bootstrap we have a matrix field, let's call it Grid, that has blocks like "full column" "half column" etc. It's extremely usable across all pages.

Now the issue is we can have only one such matrix per template. And a standard page looks like this:

[some title]
[some grid] <- Grid
[some hero image]
[again some grid] <- Grid
[some other stuff]
[even more grid at the end!] <- Grid

The only solution is to create yet another Grid field that uses the same twig code for rendering only to use it again on the same side.

The solution would be a way to put a field in an entry type but with ability to manually set the handle. So we could put the same field (Grid) and refer to them using topGrid, middleGrid and bottomGrid.

Is there any way to solve this problem?

thanks! Jan

1 Answer 1

1

The only solution is to create yet another Grid field that uses the same twig code for rendering only to use it again on the same side.

Do you need to enforce that structure or is it a "soft" restriction (meaning things won't go south if the blocks get turned around)?

If it were me, I would treat Matrix more or less like a site builder. [some hero image] and [other stuff] could also be blocks in that matrix, alongside full column and half column, you just need the appropriate code to "close up" the grid when necessary.

You would have different blocks (like Grid, Hero Unit, Ad space, etc.) and then when building the page, just insert them in the appropriate spots.

That's the canonical use of Matrix of course. If you need full control over how things are presented you don't necessarily have to build out the page in the order the blocks appear in. If you name various blocks you could filter by block type and then spit out only the blocks that would appear in that area. For example, even if there is only one hero unit, you can specify it should only appear once and then spit out the hero where it needs to go (say at the top).

If you're doing this for a client, it might be helpful to number the blocks so they put the blocks in the intended order to avoid surprises but with matrix it's pretty open ended which might be less likely what you're looking for.

Ideally we should be able to have some "default" blocks and lock 'em in place so they can't be moved or disabled... maybe in a future version of Craft.

1
  • Thanks for the answer.Yes, we treat Matrix like a site builder but we have some pretty specific pages that require rigid structure and we don't want the end-client-user to be able to add some blocks we dont want, e.g. with JS data. Also this makes the implementation a bit of a nightmare because it's one giant macro with instead of a few smaller ones: one for grid layout, one for this special data block that's used by JS animation on only one page etc. Commented Jul 29, 2015 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.