How set div in a specific position inside .tpl.php file I use views module in my website (built in drupal-7). I have a custom theme.
I have set a views-view-fields--XX.tpl.php like follows.

    &lt;?php /**`
 * Default simple view template to all the fields as a row.
 *
 * - $view: The view in use.
 * - $fields: an array of $field objects. Each one contains:
 *   - $field-&gt;content: The output of the field.
 *   - $field-&gt;raw: The raw data for the field, if it exists. This is NOT output safe.
 *   - $field-&gt;class: The safe class id to use.
 *   - $field-&gt;handler: The Views field handler object controlling this field. Do not use
 *     var_export to dump this object, as it can't handle the recursion.
 *   - $field-&gt;inline: Whether or not the field should be inline.
 *   - $field-&gt;inline_html: either div or span based on the above flag.
 *   - $field-&gt;wrapper_prefix: A complete wrapper containing the inline_html to use.
 *   - $field-&gt;wrapper_suffix: The closing tag for the wrapper.
 *   - $field-&gt;separator: an optional separator that may appear before a field.
 *   - $field-&gt;label: The wrap label text to use.
 *   - $field-&gt;label_html: The full HTML of the label to use including
 *     configured element type.
 * - $row: The raw result object from the query, with all data it fetched.
 *
 * @ingroup views_templates
 */
?&gt;



&lt;?php foreach ($fields as $id =&gt; $field): ?&gt;

&lt;?php if ($id == 'field_voti'):?&gt;
&lt;div class="uniscicampischeda"&gt;
&lt;?php endif; ?&gt;
    &lt;?php if (!empty($field-&gt;separator)): ?&gt;
    &lt;?php print $field-&gt;separator; ?&gt;
    &lt;?php endif; ?&gt;
    &lt;?php print $field-&gt;wrapper_prefix; ?&gt;
    &lt;?php print $field-&gt;label_html; ?&gt;
    &lt;?php print $field-&gt;content; ?&gt;
    &lt;?php print $field-&gt;wrapper_suffix; ?&gt;
    &lt;?php if ($id == 'distance'): ?&gt;
&lt;/div&gt;
&lt;?php endif; ?&gt;
&lt;?php endforeach; ?&gt;`
"


in order to insert some fields into a new div with a specific class.

With firebug I see the following:

&lt;td class="col-1 col-first vistacomplessiva"&gt;
    &lt;div class="views-field views-field-title nomeattivita"&gt;..&lt;/div&gt;
    &lt;span class="views-field views-field-name"&gt;..&lt;/span&gt;
    &lt;span class="views-field views-field-last-updated"&gt;..&lt;/span&gt;
    &lt;div class="views-field views-field-field-foto"&gt;..&lt;/div&gt;
    &lt;div class="views-field views-field-body descrizione"&gt;..&lt;/div&gt;
    &lt;div class="uniscicampischeda"&gt;..&lt;/div&gt;
&lt;/td&gt;


All that I want to do now is to have the div with class="uniscicampischeda" before the div with class="views-field views-field-field-foto", so that with css I will give the right attributes (I want class "uniscicampischeda" with float=right attribute)
HOw can I do that? do I have to write some code into views-view-fields--XX.tpl.php file? How?
Can anybody help me?
Thanks.
Well, there are three solutions for your problem,


Forget about the div with class uniscicampischeda and try to work with the existing classes in order to align them to right.
If you want to insert the div.uniscicampischeda, try to find out which one of the PHP lines generates the &lt;div class="views-field views-field-field-foto"&gt;..&lt;/div&gt;, then edit the .tpl file and put the DIV before that PHP line.
As the last solution and also the most complicated one, in your template.php create function hook_preprocess_views_view_fields(&amp;$var), in this function get the Views fields value and insert them in to the $var array, then in the .tpl file use those keys of the $var array as the variable that generates the corresponding value. Using this solution you will have much more freedom to theme your view output.


If you need help about any of these solutions just let me on it.