0

I have a proposed data structure like this:

Asset:

  • Title
  • Image
  • Description
  • Taxonomy term: Campaign

Campaign (taxonomy dictionary):

  • term
  • image
  • description

I am trying to make a view block that displays only the Campaign group, represented by the Campaign image. The farthest I can get is defining a relationship to tax. terms on node, and displaying all Assets with that tag. I can even Group them, which is really close to what I need. How do I solve the problem of displaying "Campaigns" as groups of assets (not the list of assets tagged with this taxonomy).

I thought I could show a list of (non-duplicate) fields where that tax. image exists (which should be once per group/aka "Campaign"). But not so far..

How do I achieve this? Have I overlooked something? I am open to different approaches or ideas..

0

If you want to group Assets just by the Campaign (taxonomy) image, you can easily set the Grouping feature under Format to the Image field.

You have to add the Relationship for the taxonomy field first, as you have found out, then you get all the information related to the referenced taxonomy term into the Views. Without that Relationship you only have the Taxonomy term ID available, as the Taxonomy reference field only stores that info.

When you add the Relationship you can add the Taxonomy image field (Campaign image). Each Asset will then show its associated campaign image in its row.

That's when you can use Group by field and set it to the Campaign image. This will split the Asset results into Campaign groups with the image field as the "group header". You will still see the image displayed in each row, which you probably don't want, so you edit the Campaign field setting in Views and choose Exclude from display. This way the image will only display in the "group header" and won't display next to each Asset result.


If you need to display more info about the Taxonomy (Campaign) in the "group header", for example the name, image, and the description, you can add all those fields to your Views, Exclude them from display, and set them all to group by.

But sometimes the styling that comes out of this strategy isn't good enough, the HTML can be a bit unexpected. You can solve that by using Custom text field after all the Taxonomy fields where you enter your own HTML with the taxonomy field values printed out through tokens. And Group only by the Custom text field.

custom text views field HTML

I've written an article about this if you need more detail: Grouping by multiple Fields in Drupal Views

  • Thanks, prkos. I did actually go with a grouping solution – Jeff Brewster Sep 12 at 22:22

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.