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
I came up with a work around
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:
This outputs HTML as:
or
...depending on the city the event is assigned to.
I can now make custom classes to display cities as different colors as such:
I'm happy with this solution and I hope it can help others in the future.
Danny Englander | Twitter | Instagram
Same problem -
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?
/---code html
.large { color: #00FF00; font-family:arial; font-size: 4pt; }\---code
/---code html
>
print $fields['title']->contentprint $fields['sum_qty']->contentprint $fields['field_po2_value']->contentprint $fields['field_po2_value_1']->contentprint $fields['field_po2_value_2']->contentprint $fields['field_po2_value_3']->contentprint $fields['field_po2_value_4']->contentprint $fields['field_po2_value_5']->contentprint $fields['[field_5_value']->contentendforeach;\---code
Provably there is a best
Provably there is a best practice, but you can print the label using
so you can print label and content like this:
Seeking a best way to do it
@espurnes -- thanks, I will
@espurnes -- thanks, I will check that out! Very helpful.
Danny Englander | Twitter | Instagram
When I am trying to
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
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?