I'm trying to output 9 separate datasets (which represent restaurant menus) while using just one content-type. The fields of this content-type are named according to day of the week, meals types (lunch, dinner) and a taxonomy of food options, i.e. 'field_monday_lunch_soup'. On the front-end, I intend to represent the data using accordions and tabs, which is why isolating specific fields is so important.

All fields (including the nine boolean fields) are part of the same content-type. When the admin submits a menu he can associate it with one of the nine restaurants.

How do I construct an if then statement to isolate fields so that I make it clear on the user-facing side that the data is associated with a specific restaurant? I want to avoid using views and various content-types because it quickly becomes overwhelming with all the various permutations.

So my php logic is something like this at the moment:

<?php if ($content['field_restaurant_one']['und'][0]['value'] == '1'): ?>

Any help would be hugely appreciated! I'm thinking EFQ (entity field query) is the way to go.

  • I'll be honest - I don't follow your setup at all. Each restaurant has a node and each node has nine boolean fields? Or each menu is a node and each menu has a boolean field for each restaurant? It seems like maybe you could simplify things by using entity references and views or possibly EFQ if you don't want to use Views (see drupal.org/node/1343708 and phase2technology.com/blog/… ) – ergophobe Mar 9 '14 at 21:30
  • Also, this is sort of an aside, but I avoid using ['und']. It's better to use field_get_items(). See api.drupal.org/api/drupal/modules!field!field.module/function/… and drupal.stackexchange.com/questions/24699/… – ergophobe Mar 9 '14 at 21:35
  • @Kirby Instead of writing comments, it's better to update your question with more details if you can provide them. That helps getting a quick idea of the problem and makes information retrieval easier. – berliner Mar 9 '14 at 23:38
  • Using booleans to this kind of purpose sounds highly unusual. They are not nearly as flexible as for instance taxonomy terms and references are. If/when you have to change anything later, you'll be in trouble. Dealing with permutations in Views would sound better to me than creating fields for each permutation (monday_lunch_soup, tuesday_lunch_soup etc.) Restaurant-weekday-dish (or whatever) data structure can be challenging. Maybe take a look at what these guys have done: drupal.org/project/restaurant – Kari Kääriäinen Mar 10 '14 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.