function views_theme_wizard_generate_list_template_code in Views (for Drupal 7) 5
generate a template file for a list theme
1 call to views_theme_wizard_generate_list_template_code()
File
- ./
views_theme_wizard.module, line 477
Code
function views_theme_wizard_generate_list_template_code($view) {
$now = format_date(time());
$header = <<<EOT
<?php
/**
* views template to output one 'row' of a view.
* This code was generated by the views theming wizard
* Date: {<span class="php-variable">$now</span>}
* View: {<span class="php-variable">$view</span>-><span class="php-function-or-constant property member-of-variable">name</span>}
*
* Variables available:
* \$view -- the entire view object. Important parts of this object are
* {<span class="php-variable">$view</span>-><span class="php-function-or-constant property member-of-variable">name</span>}, {<span class="php-variable">$view</span>-><span class="php-function-or-constant property member-of-variable">real_url</span>}.
* \$view_type -- The type of the view. Probably 'page' or 'block' but could
* also be 'embed' or other string passed in from a custom view creator.
* \$node -- the raw data. This is not a real node object, but will contain
* the nid as well as other support fields that might be necessary.
* \$count -- the current row in the view (not TOTAL but for this page) starting
* from 0.
* \$stripe -- 'odd' or 'even', alternating.
EOT;
$fields = _views_get_fields();
$taken = array();
// Set up the fields in nicely named chunks.
foreach ($view->field as $id => $field) {
$field_name = $field['field'];
$css_field_name = views_css_safe($field['field']);
if (isset($taken[$field_name])) {
$field_name = $field['queryname'];
$css_field_name = views_css_safe($field['queryname']);
}
$taken[$field_name] = true;
$output .= <<<EOT
<div class="view-label view-field-{<span class="php-variable">$css_field_name</span>}">
<?php print \${<span class="php-variable">$field_name</span>}_label ?>
</div>
<div class="view-field view-data-{<span class="php-variable">$css_field_name</span>}">
<?php print \${<span class="php-variable">$field_name</span>}?>
</div>
EOT;
$fid = $view->field[$id]['id'];
$header .= ' * $' . $field_name . ' -- ' . $fields[$fid]['help'] . "\n";
$header .= ' * $' . $field_name . '_label -- The assigned label for $' . $field_name . "\n";
}
$header .= <<<EOT
*
* This function goes in your views-list-{<span class="php-variable">$view</span>-><span class="php-function-or-constant property member-of-variable">name</span>}.tpl.php file
*/
//now we add the stylesheet...
drupal_add_css(path_to_theme() .'/views-list-{<span class="php-variable">$view</span>-><span class="php-function-or-constant property member-of-variable">name</span>}.css');
?>
EOT;
return $header . $output;
}