1

I have asked this question before but in a different, more convoluted context. This is a simpler example.

I have a paragraph type which I use Layout Builder to define it's layout. In that layout I have a View (paragraph) used to display content from that paragraph. If I add a contextual filter for Paragraph ID to my View and in Views preview I enter a PID, the View displays the correct results. But there is no way I can see to pass the PID from my layout to the view.

There is a Views option to set Block settings and enable Contextual filter which then shows up when I configure the block in LB. But this will not accept a token like [paragraph:id]; although technically it shouldn't need this as the View should know the context of where it is placed.

What am I missing here?

1
  • There is a Views option to set Block settings and enable Contextual filter which then shows up when I configure the block in LB where? I don't see it. Perhaps this is coming from a contrib module that I don't have.
    – No Sssweat
    Commented Dec 10, 2022 at 7:55

2 Answers 2

0
  • In this case, don't create a paragraph View
  • Instead, create a content View
  • Then under Advanced, add relationship to your node's paragraph field.
  • In Fields, add your paragraph fields.
  • Now you can add context of ID and grab from URL.
4
  • Yes, I have done a few views like that; but for this one there are reasons it is preferred to do this as a Paragraphs view and I am trying to understand how its possible to pass the paragraph ID, or if not, why that wouldn't be possible. As it turns out I have "hacked this in" by setting pid as a static var during paragraph_load and then wrote a new argument handler for PID which pulls this value - but can't help feeling this should be there naturally.
    – liquidcms
    Commented Dec 11, 2022 at 16:03
  • Another hacky way, to be dynamic instead or hard coded, would be to add the paragraph ID as a field in the content view, and then use Views field view and to insert the paragraph view in your content view which will pass the paragraph ID as contextual.
    – No Sssweat
    Commented Dec 12, 2022 at 2:53
  • if not, why that wouldn't be possible @liquidcms Coding wise, anything is possible, I think such feature just needs to be built. However, it probably hasn't been built because its not really needed. Most people don't use Views to display a single paragraph in LB. What most people do is 1) create a "view mode" (admin/structure/display-modes/view) 2) Enable view mode in paragraph manage display. 3) In LB insert the paragraph directly and select the "view mode" they created in step1 for the configuration setting. 4) Theme the "view mode" by creating a template file (twig) & CSS.
    – No Sssweat
    Commented Dec 12, 2022 at 3:15
  • PS: step 1 and 2 isn't mandatory. You could use "default" as your view mode if you like.
    – No Sssweat
    Commented Dec 12, 2022 at 3:29
0

I use this method: in the LB I remove all the fields and keep only the "title" field (for example) and I use "view" as a formatter of the field.

Then choose the view you created previously and as "View Arguments" I select "Entity ID".

I use this method when I need to create views that have "logic" behind that I can edit faster than creating a template / twig.

We use a lot of contrib modules and I don't know if this possibility comes from the core or from a module.

I use this method on D9.

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.