I'm looking at the best way to theme certain types (in the entity sense) of bean blocks. I was hoping I'd just be able to create separate .tpl files for each but it doesn't seem like the Bean's entity type gets factored into the candidate names. Right now I only see:
- block__REGION-NAME
- block__bean
- block__bean__BLOCK-LABEL
Is this just due to the underlying block system? Could Bean do an alter and offer more choices?
Update: I'd looked at the possibility of extending bean_plugin and implementing a view() function that called a wrapper theme function but since the bean's I'm using are exported using hook_bean_admin_ui_types() they get the default handler. I guess I could move them over to hook_bean_types() but this seems like a common usage that should be better supported.
Comments
Comment #0.0
drewish CreditAttribution: drewish commentedlist the candidates i'm seeing
Comment #1
indytechcook CreditAttribution: indytechcook commentedSince bean is an entity you should theme the bean, not the block.
So you can use hook_preprocess_bean()
function template_preprocess_bean(&$vars) {
$vars['theme_hook_suggestions'][] = 'bean__' . $vars['type'];
}
might work. One of my team mates is going to respond also.
Comment #2
indytechcook CreditAttribution: indytechcook commentedI'm very open to suggestions also. I write the low level APIs on our projects :)
Comment #3
drewish CreditAttribution: drewish commentedThis might be a kind of noob question but where is bean's theme function called? Does the Entity API handle that? I see it registered but I'm wondering where we'd add a candidate other than in the template. I'd rather have the templates work across themes if possible.
Comment #4
indytechcook CreditAttribution: indytechcook commentedThe Entity module adds the template suggestions.
?>
Comment #5
drewish CreditAttribution: drewish commentedHummm I was looking at the list of calls inside devel_themer and not seeing entity called. I'll give that a try. We're doing it inside context so I wonder if that has an effect.
Comment #6
indytechcook CreditAttribution: indytechcook commentedThanks. I'd love some insite to some better theming for bean if you have any suggestions.
Comment #7
indytechcook CreditAttribution: indytechcook commentedSo it looks like the theme suggestions are made but the it's not registering the preprocess. I'm not sure why.
https://skitch.com/indytechcook/gphj5/welcome-to-beans.dev-beans.dev
Comment #8
drewish CreditAttribution: drewish commentedAh okay so putting the bean.tpl.php in the theme got the call showing up… not sure why it wasn't there before. I'm going to play around with this a bit more I might change it to a support request and close it.
Comment #9
drewish CreditAttribution: drewish commentedOh I think this might have something to do with the preprocess: #939462-6: Specific preprocess functions for theme hook suggestions are not invoked
Comment #10
paulhhowells CreditAttribution: paulhhowells commentedWhen using Display Suite there is a need for the original issue that started this thread, i.e. a need to theme:
While (as mentioned in the thread above) it is best to theme plain vanilla beans with bean.tpl rather than block.tpl, using Display Suite will result in bean.tpl being completely overridden and block.tpl being used. Themers will then want to style block.tpl to be in harmony with the bean type (and the DS style applied to it).
I am having a go at adding to the theme_hook_suggestions for block:
This works, but only for one particular bean. Within $variables['elements']['bean'] the data that is needed to get the bean-type is nested within a number which is different for each bean. In this example the number is [4]:
$variables['elements']['bean'][4]
Obviously this code will not work if there is more than one bean, or the bean has a different number. It’s a start, but not much use in practice.
So my questions are:
I will be overjoyed if I can get this working because Beans with DS are an incredible combination! FWIW I’m a designer & themer, not a module developer, so I apologize if I have missed something obvious.
Comment #11
paulhhowells CreditAttribution: paulhhowells commentedThe following code enables block__bean__BEAN-TYPE as a block.tpl theme suggestion (when pasted into a theme’s template.php file).
However, I would love to have comments:
many thanks
Paul
Comment #12
indytechcook CreditAttribution: indytechcook commented@paul, that's really interesting. I'd be willing to add this to bean if other people agree. Also, please update http://drupal.org/node/1434622 with findings.
Comment #13
paulhhowells CreditAttribution: paulhhowells commented@indytechcook thanks! I have refined the code slightly and added a comment at: http://drupal.org/node/1434622#comment-6761032 I hope others agree, it would be really great if this was added to the bean module.
Comment #14
rooby CreditAttribution: rooby commentedFor reference, this is what I have been using (seems like some of the variable validation in the previous examples are not really needed IMO but maybe mine is too assuming?):
Adds bean type class & template suggestion:
Comment #15
rooby CreditAttribution: rooby commentedHas anyone had any luck with getting MYTHEME_preprocess_bean() to fire?
Even when I have bean.tpl.php in my theme I can't get the preprocess to fire.
Or are we doomed by #939462: Specific preprocess functions for theme hook suggestions are not invoked?
Comment #16
rooby CreditAttribution: rooby commentedHere is less pretty workaround:
Alternatively you could just use template_preprocess_entity for now and be done with it.
[EDIT] Edited to lessen the alarmist wording :)
Comment #17
seafront CreditAttribution: seafront commented@rooby why is that dodgy?
Comment #18
rooby CreditAttribution: rooby commentedWell it isn't really. I use it in a few sites and I'm not worried about it.
But it's not as nice a solution as we could have #939462: Specific preprocess functions for theme hook suggestions are not invoked
Comment #19
paulhhowells CreditAttribution: paulhhowells commentedIt seems like Context Module (and presumably others?) will break the code I originally tried.
I’m keeping a gist updated here:
https://gist.github.com/paulhhowells/4722363
Which at the moment looks like:
note to self: I must try @rooby’s solution
Comment #19.0
paulhhowells CreditAttribution: paulhhowells commentedadding some discussion of hook_bean_admin_ui_types() vs hook_bean_types().
Comment #20
saltednutUsing bean--[machine-name]--[view-mode].tpl.php works as of the latest release.
Comment #22
paskainos CreditAttribution: paskainos commentedI noticed Devel Themer is now presenting the following tpl candidate files:
This also presents
bean.tpl.php
as the base candidate template file.