How do I wrap a view row inside a ? I have bad-designed a view, and the result is that I have the following scheme: 


Field 1: Category (taxonomy) 
Field 2: Node title
Field 3: Image
Field 4: Other data (PHP processed).


The problem is that I need field 1 to appear just once for a group of nodes and not always. As I had to redo all the View, I have made the following process, please tell me if there is a better solution.

Instead of not displaying field 1, grouping by that, etc., as I have some PHP process on it, I do the following:

In views-view-fields.tpl.php I identify the category, and prepend [[BEGIN]]. I identify the last field and append [[END]].

In views-view-unformated.tpl.php I replace [[BEGIN]] and [[END]] with &lt;div&gt; wrappers; depending on the valued inside (preg_match), I make the category title  appear just once at the beginning of the list of products.

Please tell me if that is a valid approach (it works) or it should be more desirable to re-draw the view (hours of changing fields, logic, etc.).

The string replacement outputs an additional &lt;div&gt; which wraps all the complete row of fields. This I had in the view as the field 1 was just another field and did not encapsulate anything. Maybe even if I would set it as grouping field it didn't encapsulate anything. The result I want (and get) is:

&lt;div class="other-class" id="category-119"&gt; divs and HTML stuff from the view  &lt;/div&gt; 


The only easy and fast way of doing a &lt;div&gt; encapsulation of the row is using those delimiters in the template files.
Add field and Exclude from Display.
Add Global: Text area in the header.
Check Use replacement tokens from the first row
Enter the row pattern
Use css to make it look part of the first row 


That will output the first row's field in the header.