I created a view showing the latest closed quizzes, and the view file tpl.php for theming, now I need to test if a quiz is closed or not. How can I do this?
I did this in the Row style output template "views-view-fields.tpl.php":
<?php
if ($fields['quiz_close']->content!='0 sec'):
?>
<?php foreach ($fields as $id => $field): ?>
<?php if (!empty($field->separator)): ?>
<?php print $field->separator; ?>
<?php endif; ?>
<<?php print $field->inline_html;?> class="views-field-<?php print $field->class; ?>">
<?php if ($field->label): ?>
<label class="views-label-<?php print $field->class; ?>">
<?php print $field->label; ?>:
</label>
<?php endif; ?>
<?php
// $field->element_type is either SPAN or DIV depending upon whether or not
// the field is a 'block' element type or 'inline' element type.
?>
<<?php print $field->element_type; ?> class="field-content"><?php print $field->content; ?></<?php print $field->element_type; ?>>
</<?php print $field->inline_html;?>>
<?php endforeach; ?>
<?php endif; ?>
And the result is as follows:
Quiz 2
1.
2.
3.
Quiz 1
1. john
2. peter
3. martin
But only the "Quiz 1" should appear because it is already closed!
In the quiz 2 it only deleted the names, but the "if" works fine.
I tried to put in the "Style output" view template file and "Display output" view template file but the code "if ($fields['quiz_close']->content!='0 sec'):" did not work. What am I doing wrong?
obs: The "close time" field is configurated to "Time ago" date format.
Sorry for my bad English.
Comments
Comment #1
merlinofchaos commentedThis is what 'filters' are for. You shouldn't test for stuff like this in the theming.
Comment #2
gutomec commentedI know, but the filters removed the option to filter by this field. But I can add it in the fields and filter in the theming. I can't see the "Quiz: Close time" in filters.
Any idea?
Comment #3
gutomec commentedI can see the field "Quiz: Close time" in the fields section. But in the filter section i dont see it.
This is a field of the quiz module.
Comment #4
gutomec commentedNot Fixed.
Comment #5
merlinofchaos commentedFine, won't fix then -- you can't filter in theming. If you can't filter by the field then you should file an issue against that module.
Comment #6
gutomec commentedThink with me, the hierarchy for theming views is: Display output: views-view.tpl.php> Style output: views-view-list.tpl.php> Row style output: views-view-fields.tpl.php> Field : views-view-field.tpl.php. Ok?
Suppose I want to print the field whose ID is name_winner. In views-view-fields.tpl.php if I put
<?php print $fields['name_winner'] -> content;?>fields name_winner be listed.Now, suppose I want to list only the first winner's name in the views-view-list.tpl.php, as I do? That would solve my problem.
I tried
<?php print $fields['name_winner'][0] -> content;?>but no success.Thank you.
Comment #7
merlinofchaos commentedComment #8
gutomec commentedEarl,
Let active please, may be that someone else can help me. I'm not reporting a bug, I'm asking for support, if you can not help it may be that others can.
Thank you.
Comment #9
esmerel commentedit's "Won't fix". If you are still looking for help, try the forums or some other method than the views issue queue.