0

I have three content types: Newspaper, Headlines, and Local. All entities have standard Title/Body fields. Newspaper has two additional multiple value fields named Headlines and Local that are referencing the respective content types.

I ultimately would like two very similar RSS views (one for Headlines and one for Local) that would show respective nodes that are linked from a Newspaper content. I am able to do this using Views Relationships. The problem is how to display only referenced nodes that are linked from the latest Newspaper content type.

I also contemplated on the possibility of first creating a separate view that displays the latest Newspaper, but I can't figure out how to pass it to another view, if it's even possible.

Here's some concrete information: Say for example, I have the following content

Newspaper

  • June 19, 2018

  • June 18, 2018

Headlines

  • Blah
  • Bleh
  • Meh

Local

  • Something Happened
  • Nothing Happened
  • Nothing Happened again

Here's a visual on what I'm trying to get.

enter image description here

The whole reason for this is that I'm working with a newsletter application whose templates can take in several feeds. The particular template has a different style per section. I was planning to pull in a separate feed per section so the section can be styled independently. Even though the would-be feeds are separate, I need them to be in sync with one another and make sure they're pulling from the same Newspaper content.

  • Are you trying to solve the problem of filtering out the latest Newspaper? Or passing arguments between views? Or both? Do you have a way already for identifying the latest Newspaper in Views? – prkos Jun 23 '18 at 0:08
  • I am trying to solve the problem using both. I'm currently looking at using the Twig Tweak module to see if there's a way to do this there, though it might take me a while since I am not too familiar with Twig itself beyond basic templating. – johnmiste Jun 27 '18 at 13:13
  • It's not yet clear you need twig for this. It's certainly possible to pass arguments between views, but it's not clear that's what you need. You haven't clarified what your problem is, you only listed ways you're trying to solve it. You also haven't clarified what you mean by "the latest Newspaper". Is using the "Authored on" field reliable enough? Is there some other way in your project concept that identifies what the latest means? Your screenshots suggest you need help with filtering, limiting to a particular node referenced. – prkos Jun 28 '18 at 17:49
  • Using my schema above, the problem I was trying to solve is how to have a RSS view of Headlines content type, and a RSS view of Local content type that will only show items if they are referenced in single newest Newsletter content (Probably need to reword the question). I'm going to try your solution soon. Will post back here for updates. – johnmiste Jul 23 '18 at 19:48
0

You can do this with the help of the Views Field View module by embedding one View display into another.

In your case you want to have one View showing only the one latest Newspaper, and the other helper Views Display listing Headlines referring to the latest Newspaper that will be embedded into the first Display.

Here are the steps how to do it:

  1. Create a Newspaper View
  2. Add Sort criteria "Authored on" (Descending)
  3. Use pager: Display a specified number of items | 1 item

    You should now have only your latest Newspaper node listed as a result. You don't need any Relationships or Contextual filters here.

  4. Add a new field Content: ID, Exclude it from display and Rearrange fields so this one is on top
  5. Create a new Views Display of type Embed in the same Views
  6. Keep the filters (Newspaper) but override the Pager to show all items
  7. Add a new Field Content: Headline and under Multiple field settings make sure you're NOT using Display all values in the same row, it should not be ticked
  8. Add a new Contextual filter Content: ID for this display only and configure it:
    When the filter value is NOT available
    Provide default value
    Content ID from URL

    Now if you enter the node ID of the latest Newspaper node into the View Preview argument field you should see a list of Headlines referencing that node.

  9. Save the View (Important! The next step won't work without it)
  10. Edit the original View Display (from step 1 above) and add a new Field Global: View (Embed a view as a field.)
  11. Under View settings for this field select the View you're currently editing. You may need to Save the View again at this point.
  12. Then under Display option under it choose Embed and fill in the Contextual filters fields with the node ID token from the Replacement patterns below it. It will probably be something like {{ raw_fields.nid }}

You should now have a list of the latest Newspaper node with Headlines referring it also listed.

Even though the View is set to display Newspaper nodes, through the Entity reference field and an ID contextual filter you only see Headlines listed.

Descendant sorting and pager limited to one is making sure it's related only to the latest Newspaper.

Using a different View display to show Headline nodes enabled us to list them one Headline per view row. If we did that in the original Display we'd had to list them all on the same row, because if we didn't we might not get all the Headlines listed because of Pager limit. And Headline count per Newspaper probably varies so we can't predict anyway.

In the end Views Field View enabled us to embed one view into another one and pass argument to it.

Now repeat all the steps for the Local content type (clone and edit).

Your original Views Display will probably be Feed, but it would have been too complicated to include it in this explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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