1

I have a Services section in which I keep a related entry field for News. (News by Service) The News items to be displayed for each service are selected in a "News" entries field in the Service entry. For each related news entry, I need to be able to include Lightswitch booleans for "alert" and "pinned", each with different behaviors on the front end. For instance, when an admin adds a related news entry to a service, they also should be able to determine if that new entry is either an alert or a pinned news item, but only for the current service.

I'm able to included related news in each service template, but I'm unsure how to accomplish having a lightswitch that appears for each related news item in the services cp. So that, for instance, news entry A is only an alert in Service B. Or news entry C is only pinned for Service D.

I guess I could create pinnedInService and alertInService entry fields in the News section, but this seems convoluted. Maybe this is best done in the News item, rather than in the Services entry? I'd also like to be able to expire or unpin the news entries based on a date field (also per service).

Any direction on how to accomplish this? Thanks in advance!

1

You are correct, you would not want to add those fields to the news items directly. Like you said, it would cause problems if you wanted a News item pinned on one service but not pinned on another one.

The best solution here (imo) is to utilize a Matrix field (or possibly a Table or SuperTable field, depends on your preference). So I would create a Matrix field for your service entries called News Items or whatever. Than each news item block would have several fields:

  • the actual related entry field where you would pull in the news entry
  • a lightswitch field for pinned
  • a lightswitch field for alert
  • a date field you could use to expire the news block
  • etc...

This would enable you to set these settings on each news block on the individual service entries, so you're not muddying up the news items themselves or contaminating other service pages where you may want a news item "pinned" or "alerted". And again, you could also use a SuperTable or maybe even a Table field instead of Matrix - just depends on what you prefer.

| improve this answer | |
  • Thanks Jalen. That sounds promising. I'd expect the matrix blocks to be a bit cumbersome for the admin, considering the simplicity of the functional need. Lots of moving parts for a couple of small switches. I'm sure it'll work though. I've never used supertables and want to keep it first-party if possible. – Jim May 21 '19 at 1:15
  • Yeah I don't think it will be that bad at all... You could also use a dropdown or radio button field instead of multiple lightswitches if only one should be "selected" at a time. – Jalen Davenport May 21 '19 at 1:53

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.