0

I have created views called 'Awards' and in these award views they reference 'food item' nodes. Within the view a food item can be 1st, 2nd, 3rd, depending on certain filters/reasoning to create this list.

So, if a food item is 1st in an Awards view, how can I automatically put this on a 'food item' node to show that this food item has won an award?

More info on the views

They are created and sorted/filtered by specific things, one view might be 'Most calorific meal' and then it just lists meals by calories in them. Then I get a 1st, 2nd, 3rd. So if hamburger comes up as 1st, I want to put a badge on the hamburger food item node saying it's 1st in the Awards section for: Most calorific food item.

  • 1
    Views are essentially a GUI for database queries, with a bunch of fun extra stuff added on top. But at the core, it's a database query. Queries are dynamic - they are not stored, they are retrieved as necessary. As you change filters, the query is altered accordingly to retrieve the data (nodes in your case) shown in the view. So it's not possible to find out what view a node will be in, without first executing the view. – Jaypan Aug 24 '18 at 14:42
0

You could probably do that with Views, clone your Views into three Block Displays, one for each prize (1st, 2nd, 3rd).

Limit the Pager to show only one result, but for 2nd and 3rd set the Offset value to 1 and 2 respectively.

Use Contextual filters to pull node info into the View (node that the Block will be displayed on, basically all food item nodes). Set the Contextual filter settings to Hide View if there's nothing to see, in other places possibly as well.

Then display all 3 Blocks on food item nodes. If there's a "hit" for any prizes the relevant Block will be displayed on that node. If not, then the hiding should take care of it.

I don't think there's a contextual filter for Views counter, that goes a bit reverse, context from Views. It might be useful here, but alas no go.


All that said, depending on your project structure, there are probably better ways of solving this. Flag and Rules modules come to mind. You could create 3 flags, and use Rules to programmatically assign flags based on criteria (they wouldn't be flags that users use).

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.