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
<div> 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
<div> 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:
<div class="other-class" id="category-119"> divs and HTML stuff from the view </div>
The only easy and fast way of doing a
<div> encapsulation of the row is using those delimiters in the template files.