By drale01 on
Is there a module or another way to add custom fields to a Views block, where the field would be filled in when placing the block in the Block layout, similar to how "Items per block" is selected?
For example, a Background Color field where one of the predefined colors could be chosen.
Background color field when inserting Views block in Block layout
Maybe these fields should be entered into views under "Block settings" or in some other way:
Comments
I usually do this by adding a
I usually do this by adding a class in the View, or in the block with https://www.drupal.org/project/block_class.
I need something more complex
Yes, I have considered that, but how would I set up something more complex, like a responsive background image? In that case, it would have to be a field.
Or multiple different fields, for example:
What about to use a content
What about to use a content block and render a view in it with the module like Viewfield?
It is solution but...
You are right, that is one way to solve it, but it complicates things for the client since I’m using Mercury Editor. With Viewfield, the client would:
For each different block configuration, they would have to create a new block, which makes this approach a bit complicated.
Is there a way to insert the fields below "Items per block"
I think it would be easier
I think it would be easier for us to help you, if you made a use case, like "As en editor with these permissions, I want to be able to ... etc."
You helped me find a solution!
Thank you for your input! It helped me find a solution.
Instead of using Viewfield inside a Block, I will use it within Paragraphs.
Use Case:
As an editor with the necessary permissions, I want to have the flexibility to modify the appearance and structure of a Lists (Views) block without needing to create multiple blocks or manually override configurations each time.
Implementation:
I am building a theme that allows clients to make simple modifications to Lists (Views) blocks. Instead of relying on Viewfield in a Block, I have integrated it within Paragraphs, which offers a more user-friendly and reusable approach.
With this setup, the editor can:
All of these modifications are dynamically applied through a Twig template, making it easier for the client to adjust settings without creating new blocks every time they need a small variation.
This approach keeps the editing process more streamlined while leveraging the flexibility of Paragraphs.
Thanks again for the discussion—it helped me refine the solution!
Fantastic, thanks for sharing
Fantastic, thanks for sharing your use case and solution, great that you solved this task!
I have begun using use cases in issues myself, to make it clearer what is in play, like in #3504766: Allow defining a base URL. Not only does it help others to more easily understand my motivation, but it also helps in making it clearer to myself what should be taken into consideration.
I just ran into this exact
I just ran into this exact issue today, and I was not able to find a way to add/extend configuration to a views block. In the end, I went an alternate route - I created a block plugin, that has custom configuration, and renders the view.
Use case:
Solution:
With this solution, the CKeditor enabled 'header text' field is made available on layout builder, and the block admin page, when placing a block, and renders the header when the block is rendered.
Contact me to contract me for D7 -> D10/11 migrations.
@jaypan, thank you for
@jaypan, thank you for sharing your clever solution!
Thanks for sharing also
Thanks for sharing also @jaypan. It's in forum posts such as this, that images could be really useful, to demonstrate how the result looks like for the end user, in the GUI.
I am still hoping #2926532: Provide file upload for forums will happen.