Subtheme search-theme-form.tpl file only called when path from Zen folder is specified
kdebaas - January 27, 2008 - 17:49
| Project: | Zen |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
When following the README.txt instructions to override the Drupal search form, the search-theme-form.tpl.php file that I placed in the subtheme folder does not get called unless I prepend the path from the Zen directory into the subtheme template.php function:
/**
* Override the Drupal search form using the search-theme-form.tpl.php file.
*/
function phptemplate_search_theme_form($form) {
return _phptemplate_callback('/SUBTHEME/search-theme-form', array('form' => $form));
}
// */
#1
Seeing this too for a few calls to _phptemplate_callback in my subtheme.
And inexplicably, some of them work OK.
It's been driving me nuts since yesterday...
#2
Thats' because of these lines in template-subtheme.php - function _zen_hook() :
// Only create a function if $hook contains letters and underscores.if (!preg_match('/\W/', $hook)) {
This excludes templates containing a '-'. Is there a real reason for this ?
edit : bleh - of course there is. It's because the code attempts to create a function with '$hook' in it's name...
Anyway - fainally gave me the reason why some of my templates were not called :
_phptemplate_callback($hook, $vars, $suggestion);$hook cannot contain any '-'. template specialisations ('node-(..)-(..).tpl.php need to be provided through $suggestion
Thus, the sample code provided in the default SUBTHEME phptemplate should be fixed to :
/*** Override the Drupal search form using the search-theme-form.tpl.php file.
*/
function phptemplate_search_theme_form($form) {
return _phptemplate_callback('search_theme_form', array('form' => $form));
}
#3
Yep, you are correct. Hook names have to be valid php function names. BTW, this requirement is caused by Drupal core, not by Zen; take a look at how _phptemplate_callback() works.
Hmm. I got that search box code from the handbooks. Looks like a bug in those docs. http://drupal.org/node/45295 is now fixed.
The function should be:
function phptemplate_search_theme_form($form) {return _phptemplate_callback('search_theme_form', array('form' => $form), array('search-theme-form'));
}
#4
Committed.
#5
#6
This thread is somewhat confusing - what is the upshot of this?
Calls to _phptemplate_callback should have the $hook in its Drupal form, ie "user_login_block", with _ as opposed to hyphens? - yes or no?
The template files should still be named with hyphens? yes or no? Or should they now follow with the underscores??
This isn't clear from what's written here.
Edit: not crystal clear, anyway ;)
#7
Correct use is
return _phptemplate_callback('search_theme_form', array('form' => $form));
with template search_theme_form.tpl.php
#8
No, correct use is what I said in #3 above (and what is in 5.x-1.0-beta2). And the file name remains the same: search-theme-form.tpl
What Yves said in #7 will work, too. But Drupal’s naming convention has underscores in hook names and dashes in file names, so the solution in 5.x-1.0-beta2 is more correct.
#9
The most common scenarios for adding code to template.php (in my case) is for theming CCK and Views.
Views Theme Wizard outputs:
$items[] = _phptemplate_callback('views-list-MyView', $vars);But CCK theming (as from cck/theme/README.txt) behaves:
return _phptemplate_callback('field', $variables, array('field-'. $field['field_name']));Now I am willing to accept that this is a bug in Views theme export, and I should scurry over there and file an issue. But two questions bother me:
_phptemplate_callback('pathtosubtheme/views-list-MyView', $vars);hyphens and all?#10
Because you aren’t creating sub-themes of other themes. The problem occurs because Drupal 5 gives sub-themes a second-class status. There are things you can't do “out of the box” in a normal sub-theme.
There is code in the Zen theme that tries to fix the limitations on sub-themes imposed by D5.
Without the subtheme folder prepended to the hook, _phptempalte_callback() first looks for the function called
_phptemplate_views-list-MyView(). But since there are dashes in that name, it's not a valid function name. Then it calls_phptemplate_default()which in turn looks for a file called views-list-MyView.tpl.php.When you add the sub-theme folder, it looks for a function
_phptemplate_pathtosubtheme/views-list-MyView()and then for a file called pathtosubtheme/views-list-MyView.tpl.php.So it is a bug in the Views Theme Wizard. I've submitted a patch: http://drupal.org/node/215570
And, I've re-opened this Zen issue http://drupal.org/node/196181 until the bug gets fixed in Views.
#11
...aaaand again, what's the "official" workaround for this Views bug, if there is one? Thanks! :)
#12
NikLP, that would be to correct
_phptemplate_callback('views-list-VIEWNAME', $vars);from Views Theme Wizard output into
_phptemplate_callback('views_list_VIEWNAME', $vars, array('views-list-VIEWNAME'));#13
Yep, Klass is correct.
#14
Is that how the callback is rendered in the code exposed by the Views theme wizard then...? So we'd have to hack the output files basically yeah?
I'm just being obtuse on purpose so that anyone reading this thread has a complete plan of what to do :)
#15
Automatically closed -- issue fixed for two weeks with no activity.
#16
Hm, I ran into the same problem and tried everything that is suggested here, put still the only ways that work are putting the .tpl.php file to the folder one level above or adding the subtheme folder name (which was the original problem here). Everything else gives me
<!-- PHPTemplate was instructed to override the views_list_VIEWNAME theme function, but no valid template file was found. -->#17
Yan, in views_list_VIEWNAME, did you replace
VIEWNAMEwith the actual name of your view?#18
Yes I did, marcvangend.
#19
Yan, since you are trying to override a Views Theme Wizard view, this is the correct issue: #196181: Views Theme Wizard: _phptemplate_callback doesn't look in sub-theme folder for .tpl.php files
If you are going to re-open a closed issue, at least open the right one! ;-)
#20
tracking this issue
#21
Nicolas, the issue is closed (i.e. FIXED!) And Yan’s issue is a duplicate of a different issue. So there’s nothing to track.
#22
Sorry JohnAlbin, meant to say "bookmarking" issue, planning on doing some things with search-theme-form.tpl, and wanted to have a way of remembering, sorry for posting on a closed issue.