> **[what if I want to use html and php][1]**

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][2]

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][2]][2]


  [1]: http://drupal.stackexchange.com/questions/188892/how-to-output-view-content-as-grid-in-custom-template/188902#comment-229020
  [2]: https://i.sstatic.net/JDJ1q.jpg