0

Can I create a different row template for every row in a view? Something like views-view-fields--foobar--0.tpl.php, views-view-fields--foobar--1.tpl.php and so on? My goal is to create a slideshow width different template for every frame.

0

Out of the box with views? No. The row templates apply to all the rows in a given view.

You could do something like this with a custom module though...

You can use hook_views_pre_render to step through your view, like so:

function mymod_views_pre_render(&$view){
    if($view->name == "yourviewname"){
      $count = 0;
      foreach($view->result as &$row){
          $row->template = dostuffhere($row, $count);
          $count ++;
      }
    }
}

In this example, you would step through each of the result rows and and create printable content. The dostuffhere() function would be a routing function that would load in the appropriate template files, which you could define using hook_theme (example on how to call with a template file is in the comments). The custom .tpl.php files from hook_theme could be called like with the theme() function.

The routing function would then look something like this:

function dostuffhere($data, $row){
switch ($row) {
    case 0:
        return theme('mymodule_template1', array('$row'=>data));
        break;
    case 1:
        return theme('mymodule_template2', array('$row'=>data));
        break;
    //etc...
}

Because, in this example, we're using reference variables in hook_views_pre_render, the "template" variable will become available in the row output for the view. So all you really need to do in your row view is to just print out the $template var.

  • Thanks for the reply, but I don't know hot to access to the data passed to the template. My theme hook return this array: 'slideshow_1' => array('variables' => 'row' => NULL), 'template' => 'views-view-fields--slideshow')) But I can't find any $row variable in the template. – alez Jul 16 '15 at 15:25
0

you can able to create a different template foe the fields which are present in the view, you can find the field template reference in , go to advanced tab in the you can able to find Theme:Information by clicking the Information Text you can able to find the template for every fields that are available in the view....

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.