0

I need to add short descriptions for some 20+ views and display them above the views. I know I have an option to add a header to a view, but that's not what I want. I have a sidebar on the left and the main content on the right which displays views on the views pages. I need to add different descriptions for my views ABOVE both sidebar and main content.

How do I achieve it?

5
  • Have you tried creating a block and placing it in a region in /admin/structure/block ?
    – No Sssweat
    Jun 6 '18 at 1:33
  • Yes. The thing is, I need different content in this block depending on the current view. So I'd need to create 20+ different blocks for each of my views which seems redundant. I'm sure there must be more elegant solution.
    – mikebrsv
    Jun 6 '18 at 1:40
  • 1. In "Header" you have option to use tokens if you need different description depending on view content. 2. If that does not solve your problem, are you okay with a solution where you have to write custom code in your theme template file ? Jun 6 '18 at 2:39
  • 1. You mean view header? I know. But I need this content to appear not in the view header, but in the region above the view. 2. Yes I am.
    – mikebrsv
    Jun 6 '18 at 2:50
  • Have you already tried adding code in template file ? May I know what did you try ? Or If you can be more specific about your need(what exactly should be in description you want), then I may try helping with code. Jun 6 '18 at 3:05
0

Yes. The thing is, I need different content in this block depending on the current view. So I'd need to create 20+ different blocks for each of my views which seems redundant. I'm sure there must be more elegant solution.

Create a block and use template_preprocess_block to alter the content based on the path. In your theme's template.php add:

mytheme_preprocess_block(&$vars) {
  if ($vars['block']->bid === 'target_block_id') {
    $path = current_path(); // gets the current page path. 

    switch($path) {
      case path1: 
         $vars['content'] = "Hello World";
         break;
      case path2: 
         $vars['content'] = "Hello Kitty";
         break;
       // ... and so on and so forth.
    }

  }
}

Note: replace mytheme with your actual theme name, same for 'target_block_id'.


Another possible option, would be to add a header to your views, and then just use CSS with absolute position to move it, this would mean you'll need to add some padding-top: or padding-bottom on some other div to create a space for it.

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.