1

Say I am writing a page template to show the daily special menu of a restaurant. Each menu item is a content and has a field to store which day of a week it goes on special. The page will have 7 tabs(Mon, Tue, Wed etc) to display the query of that day.

I wonder how to achieve this in drupal 8?

  • If you have only one node for each day you don't need views. – Maria Kvitova Mar 11 '16 at 21:31
1

A simply solution is to use 7 regions for each day and put a view block in each of them.

More flexible is a solution in page preprocess putting the view block in variables:

foreach ( $days as $day ) {
  $variables['view_block_' . $day] = views_embed_view('menu_view', 'block_' . $day);
}

And use the variables in a similar twig loop.

Think about holidays or other special cases, in code you can realize all these things. If it gets more complicated, use contextual filters and arguments as third parameter of views_embed_view().

  • I don't think he needs views if there is only one node for specific day of the week. – Maria Kvitova Mar 11 '16 at 21:27
  • Thx for the help. Just notice that there is a embed option when adding a display in view, though it seems to do nothing but provide a more meaningful parameter name to be used in the views_embed_view($name, $display_id = 'default') function. – MuSaka Mar 14 '16 at 6:39

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.