I have a custom views 2 theme called:

views-view-fields--date-browser-theme.tpl.php

My fields are:

<?php print $fields['title']->content ?>
<?php print $fields['field_event_link_text_value']->content ?>
<?php print $fields['field_event_time_value']->content ?>
<?php print $fields['field_sponsored_event_value']->content ?>
<?php print $fields['field_eventlink_url']->content ?>
<?php print $fields['field_event_location_value']->content ?>

The fields listed above output data and they are working and showing data as expected, I can tweak CSS, reorder fields, that was my goal in creating the custom template.

However, the only issue is that in my view I have some custom label names for various fields and I cannot figure out how to show these in my custom view template. For example for field_event_location_value I have "City:" as the label name and it worked fine before I created my custom view theme so now I need some guidance on how to display this in my custom view theme template.

So instead of the expected output for Location for example which should be: City: Boston, I just get Boston -- Note "City" is the custom field label in views that renders fine with a default template but does not render with my custom template above, only the data itself does.

Comments

danny englander’s picture

I came up with a work around for this in case anyone encounters this issue in the future.

I ended up reverting back to the default views output and did away with my custom template. The reason I did it in the first place was so I could have a custom CSS class for Location. In other words I have events assigned to cities like New York and Boston and I wanted them color coded with CSS. It worked in my custom views template but as I stated in the original post, my custom labels / field names were not being rendered like they are in default views without a custom template.

Now for the solution:
So for the City field in my view, I checked the box called: "Rewrite the output of this field"
In the box I can put my custom field and wrap it with some CSS that calls the field as a class.

Here is my code for the rewrite box:

<div class="[field_event_location_value]">[field_event_location_value]</div>

This outputs HTML as:

<div class="New York">New York</div>

or

<div class="Boston">Boston</div>

...depending on the city the event is assigned to.

I can now make custom classes to display cities as different colors as such:

.page-events .York

{color: #2D73A4;}

.page-events .Boston

{color: #86AC18}

I'm happy with this solution and I hope it can help others in the future.

joeko’s picture

Hello
I created block with some fields named these fields with custom labels. I want to change fonts and colours for each field. I created a template file for view which overrides the output of the view. I have some custom label names for various fields and I cannot figure out how to show these in my custom view template. When I created my custom view, and wrapped fields with CSS, my custom labels disappeared. (take a look on my block www.no-nekupto.sk)

Example: field:['sum_qty'] -counting how many product was sold. I named this field with custom label ("Množstvo predaných zliav"). When I copied template file(template file see below) my fonts and colours changed as I expected but my custom labels disappeared.

Block before I copied template file:

Názov zľavenky: Originálny SPINNING za 1.50€ v Námestove? No nekup to!
Množstvo kúpenych zliav: 22
Pôvodná cena: 3 Eura
Cena so zľavou: 1.50 Eur
Zľava: 5O%
Ušetríte: 1.50 Eur
Zľavenku si môžte kupiť ešte:
Čas pre nákup zľavy vypršal
Počet kupónov je obmedzený na: 180
Množstvo predanych kupónov potrebných pre aktiváciu zľavy: 50

Block after I copied template file:

Originálny SPINNING za 1.50€ v Námestove? No nekup to!
22
1.50 Eur
5O%
1.50 Eur
180
50

All custom labels disappeared.

I would to theme keep custom labels?

// $Id: views-view-fields.tpl.php,v 1.6 2008/09/24 22:48:21 merlinofchaos Exp $
/**
 * @file views-view-fields.tpl.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->content: The output of the field.
 *   - $field->raw: The raw data for the field, if it exists. This is NOT output safe.
 *   - $field->class: The safe class id to use.
 *   - $field->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->inline: Whether or not the field should be inline.
 *   - $field->inline_html: either div or span based on the above flag.
 *   - $field->separator: an optional separator that may appear before a field.
 * - $row: The raw result object from the query, with all data it fetched.
 *
 * @ingroup views_templates
 */

/---code html

.large { color: #00FF00; font-family:arial; font-size: 4pt; }


\---code

/---code html

>
print $fields['title']->content
print $fields['sum_qty']->content
print $fields['field_po2_value']->content
print $fields['field_po2_value_1']->content
print $fields['field_po2_value_2']->content
print $fields['field_po2_value_3']->content
print $fields['field_po2_value_4']->content
print $fields['field_po2_value_5']->content
print $fields['[field_5_value']->content

endforeach;


\---code

espurnes’s picture

Provably there is a best practice, but you can print the label using

<?php
print $fields['sum_qty']->label
?>

so you can print label and content like this:

<?php
print $fields['sum_qty']->label;
print $fields['sum_qty']->content;
?>

Seeking a best way to do it

danny englander’s picture

@espurnes -- thanks, I will check that out! Very helpful.

JagPHP’s picture

When I am trying to print
print $fields['title']->content;
its not showing up the value rather showing error: Undefined variable: fields
same goes when I use

print $rows['title']->content;
print $row['title']->content;

however it prints complete object when I use
echo '<pre>',print_r($row).'</pre>'

not sure how to render field values in my custom theme. I have 2 fields in my view title and description.
Is there anyway I can get those values so that I can customize my block with html?