Forum
Blocks limit (max=5) request
I would like to have a maximum number of occurrences for a block-type in Perch.
I'm using blocks to facilitate 'optional' fields.
Fields or collections of fields that are not always used in a region's item.
It serves the overal UI if unused fields are not on screen. So the blocks functionality helps me with that.
Simple use case without blocks is: I have a repeating region of type 'paragraph-text-block' .
The template for this contains 4 fields:
- a heading
- a subheading (optional field)
- an image field (optional field)
- the actual text field
The image field and the subheading field are optional. But they can only be entered once for one paragraph.
So with Blocks I created a block for the image and the subheading. But I only want the user to add max 1 of each.
Hope this makes sense and hope you can fit it in!
(Max blocks was also asked about in this thread:
https://forum.grabaperch.com/forum/04-06-2015-perch-blocks-limit)
Thx, René
That makes a lot of sense. We'll see what we can do!
That is a nice answer, thanks!
Did this ever get implemented?
I'm curious if there is a Blocks-limit function in Perch 3? That would help me a lot!
I just heard Drew say on the Perch podcast 57 that it will be implemented in version 3. So yay!
Edit Jan 2018: On podcast 57, at timestamp 23:19 - Drew says he added 'max options for blocks, categories, relationships' and explains it as you can set 'how many items can be added'. Today I cannot find anything about this in the docs and I've tried this in Perch, but I couldn't get it to work.
The solution James mentions (with perch_item_index) doesn't work on the side of the editor. Only at 'output' (website) time. And also when I put this around each block, it will only take the maximum mentioned in the first block and shows only that amount of blocks. So i'm thinking this tag is not made for using around <perch:block></perch:block>.
That's great! Thanks for the update, I haven't had a change to listen to the podcast yet.
Here is how to do it:
<perch:blocks> <perch:if id="perch_item_index" match="lt" value="3"> <perch:block> <your content goes here> </perch:block> </perch:if> </perch:blocks>
The number of blocks displayed will be one less than the value number.