1

I'm building a website on ExpressionEngine 3.5.10. One of the channels, training, is for Training courses.

It's possible that each training course has multiple: date, time, location, price. In other words it's the same course but that runs on different dates, in different locations, and costs a different amount.

My plan so far has been to add multiple channel fields to my training channel, e.g.

date_1
time_1
location_1
price_1

date_2
time_2
location_2
price_2

date_3
time_3
location_3
price_3  

...

Obviously this isn't ideal as I'm having to pre-determine what the maximum number of options is for the client who will be populating this content.

My strategy in the template is equally bad. For example a course must have a price to be bookable so I was going to do things like this:

{if price_1}
    // Show details and booking button for first course...
{/if} 

The idea of the above code is that if there are, for example, only details for 2 options it will output those, but {foo_3} will be omitted from the output as it's inside an {if} statement that would evaluate as false.

Is there a better way of doing this, or an EE 3.x plugin which allows the user to assign multiple options with different fields (date, time, location, price) against an individual channel entry?

Any help would be appreciated.

Please note - I don't want to have to create separate channel entries to do what I'm trying to achieve. This is because each course also has other channel fields (e.g. description, downloadable PDF) and I don't want the administrator to have to re-enter or copy/paste that every time. I want individual entries, with multiple date/time, location and price options.

The way the data is structured, conceptually, is like this:

  • Course ABC

    • Description
    • Downloadable file
    • Date 1
    • Time 1
    • Location 1
    • Price 1
    • Date 2
    • Time 2
    • Location 2
    • Price 2
  • Course DEF

    • Description
    • Downloadable file
    • Date 1
    • Time 1
    • Location 1
    • Price 1
    • Date 2
    • Time 2
    • Location 2
    • Price 2
    • Date 3
    • Time 3
    • Location 3
    • Price 3

    ...

  • Course XYZ

    • Description
    • Downloadable file
    • Date 1
    • Time 1
    • Location 1
    • Price 1

So as you can see, all courses have a Description and Downloadable file. ABC, DEF, and XYZ are individual channel entries. But each one has a variable number of date, time, location and price data.

1 Answer 1

3

Easy, I'd create a grid field with Date | Time | Location | Price.

For ease of management I'd create a separate channel for locations (manage all locations separately to stop typos and misspellings etc) and have them as relationships in the grids 'location' column. This will allow you to have detailed info for locations if required.

Looping through grid data is straight forward and your template logic would be super simple.

1
  • Perfect. A far better way than what I had! :)
    – Andy
    Commented Aug 14, 2017 at 13:25

Your Answer

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

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