1

On my site, content type Lead has field Rating (1-5). Content type Recruiter also has field Rating (1-5).

I want to have a specific "display": a list of Leads, sorted by rating, where equal-rated leads are grouped, and the group is labeled and collapsible via jQuery.

I have implemented this by creating 5 custom blocks of a view, each block selects leads rated 5, leads rated 4, ... and then I put the blocks on a page, via layout, and override block--views-block--rated-lead-block-1.html, block--views-block--rated-lead-block-2.html, ... for the total of 5 template files, to allow each rating to be collapsible via jQuery.

Well, this isn't very portable. And what if I want to have the same view for the Recruiter, not just the Lead? I don't want to create 5 template files for this for Recruiter content type, because what happens if I created another rated content type?

It seems, what I want is, instead of unformatted list, create another formatter, call it RatedItems or whatever, where I override the template file once, and the template renders all the 5 ratings, labeled and collapsible, regardless of the content type.

Is there a way to create a formatter? My available formatters are: grid, html list, table, unformatted. I want to add one more: RatedItems, and write a template for it. Is that possible?

2
  • 1
    Does this help you drupal.org/docs/creating-custom-modules/… ?
    – berliner
    Commented Sep 5, 2023 at 22:10
  • @berliner thanks for the suggestion, I'm still looking into it. Another question: lets's say I need a view City, and in it I have views Restaurants and Newsitems, and both of those need to select eg Restaurants with eg city_slug='chicago'. Instead of creating a view for each city, how would I pass parameters into views? If you can link a relevant docs page, that would be great. Commented Sep 8, 2023 at 21:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.