Convert theme() functions into views-themeable tpl.php's
lefnire - October 23, 2009 - 20:27
| Project: | Views Slideshow |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
I've been playing with the theme_* functions of views_slideshow and I can't find one that lets me theme just the breakout -- node_view() is used no matter what (whether teaser or full-node). It would be nice to let themers create a tpl.php file or a phptemplate function for the breakout of particular views (rather than particular content-types, which is addressed in #349263). I changed some code so that I could do just that on my own site, but I'm wondering if there's a better solution or something I'm missing that allows for breakout-theming:
Index: contrib/views_slideshow_thumbnailhover/views_slideshow_thumbnailhover.theme.inc
===================================================================
--- contrib/views_slideshow_thumbnailhover/views_slideshow_thumbnailhover.theme.inc (revision 1566)
+++ contrib/views_slideshow_thumbnailhover/views_slideshow_thumbnailhover.theme.inc (working copy)
@@ -61,8 +61,12 @@
drupal_add_js(drupal_get_path('module', 'views_slideshow') .'/js/jquery.cycle.all.min.js', 'module');
}
$output = '<div id="views_slideshow_thumbnailhover_teaser_section_' . $id . '" class="views_slideshow_thumbnailhover_teaser_section">' . "\n";
+
+ // Allows theming the breakout section
+ $breakout_theme = 'phptemplate_views_slideshow_'.$view->name.'_'.$view->current_display.'_breakout';
foreach ($view->result as $count => $node) {
- $output .= theme('views_slideshow_thumbnailhover_no_display_teaser', node_view(node_load($node->nid), $teaser, FALSE, FALSE), $id, $count);
+ $breakout = (function_exists($breakout_theme)) ? call_user_func($breakout_theme, $node->nid) : node_view(node_load($node->nid), $teaser, FALSE, FALSE);
+ $output .= theme('views_slideshow_thumbnailhover_no_display_teaser', $breakout, $id, $count);
}
$output .= "</div><!--close views_slideshow_thumbnailhover_no_display-->\n\n";
return $output;
#1
Actually, something that might work is if views_slideshow were a views attachment style, rather than a standard view style. This would have the following benefits:
If it sounds good, I'm more than willing to help code
#2
I still think it the breakout should be a views attachment (or an option for such, like gmap does) in order to work with 3rd-party style-plugins like carousel.
In any case, here's a new roll of the patch to provide a themeable breakout. This version actually uses proper views theme api so that you can create something like views_slideshow_breakout--stories--block-3.tpl.php, or the equiv. phptemplate_ function. I realize I should be rolling patches against dev rather than beta2, I'll have to rewrite this when I get the chance.
#3
#4
here's the -dev re-roll
#5
This looks very interesting. I will try and give it a look over soon.
#6
subscribing
EDIT: I had to read up on attachment displays, they're a little gem of Views I didn't even know existed! here's what Google turned up on attachment displays, if anyone else is wondering what the heck they are.
I believe attachment displays could do a lot for this module. Possibly making it the ‘one slideshow/carousel module to rule them all’. It would be nice to end the confusion! You may be on to something here lefnire.
My use case is to have a bunch of inline thumbnails (or possibly in a grid), which just show the larger version of themselves on hover (maybe with another field). I'd also like to be able to select multiple files uploaded to the same node as thumbnails and do the same, but that's probably beyond the scope of this issue.
#7
Ok, I took a stab at re-writing a patch for the latest -dev, but there are so many theme functions now that it would be a pretty big overhaul. Providing theme-overrides is awesome, props; however, when you use hook_theme() to provide those overrides, the override can only happen once... meaning you can only provide a custom theme for the breakout, teasers, etc for one view. If anyone has multiple views_slideshow views on their site, they can't custom-theme each of them.
The solution is to move every theme() function into a tpl.php, and register each as an 'additional theme' in views_slideshow.views.inc. For each of these themes, put markup-generating code in the tpl.php, and do logic heavy-lifting in template_preprocess_{THEME}(). See how calendar.module does it for example, calendar.views.inc[line 203], theme.inc, etc.
I'm more than willing to code this, if you'll let me; however, my first patch was ignored, so I don't want to waste time on coding if you don't want it.
The long-term solution, IMO, is still to convert this whole module into a views-attachment, so that you can swap the teasers component with any grid/carousel/whatever style (ala #6) :)
#8
@lefnire honestly I'm not ignoring it it's just my main job has me running at the moment. I encourage you to try to create a patch and let others comment on it. As soon as I can I'll get back to this.
#9
Just a small note (I didn't investigate on all sllideshow theme functions).
In the slideshow_thumbnailhover_no_display_section it checks if the display is in fields or node mode.
But after this, it renders fields/node skipping the usual (views)way to produce the output.
<?php$rendered_field = $view->field[$field]->advanced_render($node);
if (($use !== 0) && !empty($rendered_field)) {
$rendered .= '<div class="views-field-'. views_css_safe($view->field[$field]->field) .'">';
$rendered .= $rendered_field;
$rendered .= '</div>';
}
}
?>
This doesn't allow any overwrite of the rendering using the usual convention.
Let's say my slideshow view is called videotest. If I want to change the output of this section I need to edit the function itself, while would be easier to simply add my function mytheme_views_view_field__videotest__field_alias_value to theme single pieces.
So the above part should be patched with something like:
<?phpif($use) {
$rendered .= $view->field[$field]->theme($node);
}
?>
#10
Attached the patch for #9.
Indeed I found that, even if the plugin is activated, drupal runs the regular views queries.
Would not be better then use the normal output for Main frame fields and use the settings only for Breakout fields, at least to format the rows?
All the drupal_add_js in the
views-slideshow-thumbnailhover.tpl.phpcould be moved to a preprocess function.