Skip to main content
replaced http://drupal.stackexchange.com/ with https://drupal.stackexchange.com/
Source Link

what if I want to use html and phpwhat if I want to use html and php

Ok, now that I remember there is another method.

Add the following code to the bottom of your template.php file (located in /sites/all/themes/yourtheme/ folder)

function themename_preprocess_views_view_fields($vars){

      if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
        $vars['fields']['title']->content = // do php or whatever you want to it here
      }
    }
  • replace themename with your theme name
  • replace view_name with your view name
  • replace block_1 with your machine name

To add html, Ex:

function themename_preprocess_views_view_fields($vars){
    
  if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
  $a = $vars['fields']['title']->content;
  $vars['fields']['title']->content = "<div class='others'>" . $a . "</div>";
  }
}

With this method your grid should remain intact.

enter image description here

what if I want to use html and php

Ok, now that I remember there is another method.

Add the following code to the bottom of your template.php file (located in /sites/all/themes/yourtheme/ folder)

function themename_preprocess_views_view_fields($vars){

      if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
        $vars['fields']['title']->content = // do php or whatever you want to it here
      }
    }
  • replace themename with your theme name
  • replace view_name with your view name
  • replace block_1 with your machine name

To add html, Ex:

function themename_preprocess_views_view_fields($vars){
    
  if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
  $a = $vars['fields']['title']->content;
  $vars['fields']['title']->content = "<div class='others'>" . $a . "</div>";
  }
}

With this method your grid should remain intact.

enter image description here

what if I want to use html and php

Ok, now that I remember there is another method.

Add the following code to the bottom of your template.php file (located in /sites/all/themes/yourtheme/ folder)

function themename_preprocess_views_view_fields($vars){

      if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
        $vars['fields']['title']->content = // do php or whatever you want to it here
      }
    }
  • replace themename with your theme name
  • replace view_name with your view name
  • replace block_1 with your machine name

To add html, Ex:

function themename_preprocess_views_view_fields($vars){
    
  if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
  $a = $vars['fields']['title']->content;
  $vars['fields']['title']->content = "<div class='others'>" . $a . "</div>";
  }
}

With this method your grid should remain intact.

enter image description here

added 15 characters in body
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91

what if I want to use html and php

Ok, now that I remember there is another method.

Add the following code to the bottom of your template.php file (located in /sites/all/themes/yourtheme/ folder)

function themename_preprocess_views_view_fields($vars){

      if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
        $vars['fields']['title']->content = // do php or whatever you want to it here
      }
    }
  • replace themename with your theme name
  • replace view_name with your view name
  • replace block_1 with your machine name

To add html, Ex:

function themename_preprocess_views_view_fields($vars){
    
  if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
  $a = "Hello";$vars['fields']['title']->content;
  $vars['fields']['title']->content = "<div class='others'>" . $a . " World" . "</div>";
  }
}

With this method your grid should remain intact.

enter image description here

what if I want to use html and php

Ok, now that I remember there is another method.

Add the following code to the bottom of your template.php file (located in /sites/all/themes/yourtheme/ folder)

function themename_preprocess_views_view_fields($vars){

      if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
        $vars['fields']['title']->content = // do php or whatever you want to it here
      }
    }
  • replace themename with your theme name
  • replace view_name with your view name
  • replace block_1 with your machine name

To add html, Ex:

function themename_preprocess_views_view_fields($vars){
    
  if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
  $a = "Hello";
  $vars['fields']['title']->content = "<div class='others'>" . $a . " World" . "</div>";
  }
}

With this method your grid should remain intact.

enter image description here

what if I want to use html and php

Ok, now that I remember there is another method.

Add the following code to the bottom of your template.php file (located in /sites/all/themes/yourtheme/ folder)

function themename_preprocess_views_view_fields($vars){

      if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
        $vars['fields']['title']->content = // do php or whatever you want to it here
      }
    }
  • replace themename with your theme name
  • replace view_name with your view name
  • replace block_1 with your machine name

To add html, Ex:

function themename_preprocess_views_view_fields($vars){
    
  if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
  $a = $vars['fields']['title']->content;
  $vars['fields']['title']->content = "<div class='others'>" . $a . "</div>";
  }
}

With this method your grid should remain intact.

enter image description here

added 143 characters in body
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91

what if I want to use html and php both, (say) foreach(view[field]) add html div with some class? That's the only reason, i'm chasing tpl method. Because we can not use php itself to generate output in views.what if I want to use html and php

Ok, now that I remember there is another method.

Add the following code to the bottom of your template.php file (located in /sites/all/themes/yourtheme/ folder)

function themename_preprocess_views_view_fields($vars){

      if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
        $vars['fields']['title']->content = // do php or whatever you want to it here
      }
    }
  • replace themename with your theme name
  • replace view_name with your view name
  • replace block_1 with your machine name

To add html, Ex:

function themename_preprocess_views_view_fields($vars){
    
  if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
  $a = "Hello";
  $vars['fields']['title']->content = "<span"<div class='others'>" . $a . " World" . "</span>";div>";
  }
}

With this method your grid should remain intact.

enter image description here

what if I want to use html and php both, (say) foreach(view[field]) add html div with some class? That's the only reason, i'm chasing tpl method. Because we can not use php itself to generate output in views.

Ok, now that I remember there is another method.

Add the following code to the bottom of your template.php file

function themename_preprocess_views_view_fields($vars){

      if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
        $vars['fields']['title']->content = // do php or whatever you want to it here
      }
    }
  • replace themename with your theme name
  • replace view_name with your view name
  • replace block_1 with your machine name

To add html, Ex:

function themename_preprocess_views_view_fields($vars){
    
  if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
  $a = "Hello";
  $vars['fields']['title']->content = "<span class='others'>" . $a . " World" . "</span>";
  }
}

With this method your grid should remain intact.

enter image description here

what if I want to use html and php

Ok, now that I remember there is another method.

Add the following code to the bottom of your template.php file (located in /sites/all/themes/yourtheme/ folder)

function themename_preprocess_views_view_fields($vars){

      if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
        $vars['fields']['title']->content = // do php or whatever you want to it here
      }
    }
  • replace themename with your theme name
  • replace view_name with your view name
  • replace block_1 with your machine name

To add html, Ex:

function themename_preprocess_views_view_fields($vars){
    
  if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
  $a = "Hello";
  $vars['fields']['title']->content = "<div class='others'>" . $a . " World" . "</div>";
  }
}

With this method your grid should remain intact.

enter image description here

added 1 character in body
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91
Loading
added 247 characters in body
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91
Loading
Source Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91
Loading