By kalashari on
Hi,
Is it possible to use several instances of basically the same function inside template.php
Like, I have a function for a bonus view grid:
function channel_nine_views_bonus_view_grid($view, $nodes, $type) {
drupal_add_css(drupal_get_path('module', 'views_bonus') .'/views_bonus.css');
$fields = _views_get_fields();
$content = '<table class="view-grid view-grid-' . $view->name . '">';
$count = 0;
$total = count($nodes);
foreach ($nodes as $node) {
$item = '';
if ($count % 2 == 0) {
$content .= '<tr>';
}
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== FALSE) {
if ($field['label']) {
$item .= "<div class='view-label view-label-$field[queryname]'>" . $field['label'] . "</div>";
}
$item .= "<div class='view-field view-data-$field[queryname]'>" . views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view) . "</div>";
}
}
$content .= "<td class='view-grid-item'><div class='view-item view-item-$view->name'>$item</div></td>\n";
$count++;
if ($count % 2 == 0 || $count == $total) {
$content .= '</tr>';
}
}
$content .= '</table>';
if ($content) {
return $content;
}
}
Now, I would like to use that function only that I want my grid to be with let's say 5 columns... I want to use it for a different view... How do I do that? Do I make a new function inside template.php with different name than original?
k.
Comments
Yes it is
you just need to name each function with that view's name i.e.
function YOUR_TEMPLATE_NAME_views_bonus_view_grid_YOUR_VIEW_NAME
Need help with grid view theming
Hi Darko,
I was happy to have stumbled across your response and wanted to seek further insight from you on bonus grid view theming. How do we theme the grid view with a tpl file? Can't seem to do it using the Theme Wizard. I even used the following function and tpl file all of which were generated by the Theme Wizard.
Here is the name of the tpl file generated, views-list-VIEW_NAME.tpl.php
Here is the function the theme wizard told me to use:
and here is the theme function that I pulled out of the bonus grid view module
The put both these babies in my template.php file and then modified the tpl file to see if changes in tpl will be reflected in the grid view. Any changes in the tpl file were reflected only when I converted the view to list view but when I selected bonus grid view, the changes in the tpl file are not reflected. I hope this makes sense. Looking forward to hearing back from you. Thank you.
I Believe the theme wizard
I Believe the theme wizard only works for "List Views" as of now.
if you take a look of the filename "views-list-VIEW_NAME.tpl.php"
you can see it is for list views.
theme wizard only for lists - but you can create your own tpl
Yes that's correct, The Wizard only works for list type views. However, you can create your own .tpl.php file for the grid view by placing a call to a phptemplate function in your template.php, passing along the variables you need, and returning your .tpl.php file. I've done the same thing with table views and it's actually quite simple.
Jen
*~ current projects: www.intowine.com, www.researchsolar.com, www.dogstardaily.com ~*
subscribing
chris
http://SocialNicheGuru.com
Delivering inSITE(TM), we empower you to deliver the right product and the right message to the right NICHE at the right time across all product, marketing, and sales channels.
please, I need a light about this
Please, can you show here an example of your code?
I would like style each field and load the images from diferent sources, depend of the theme selected by the user.
thanks in advance
I've been having the same
I've been having the same problem for a while but got nowhere. I tried combining both functions into one, but had no success. Here's my progress so far, in case it helps anyone: http://drupal.org/node/339760