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));
}
// */

Comments

yched’s picture

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...

yched’s picture

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));
}
johnalbin’s picture

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'));
}
johnalbin’s picture

Title: Subtheme search-theme-form.tpl file only called when path from Zen folder is specified » sub-theme's search-theme-form.tpl is ignored

Committed.

johnalbin’s picture

Status: Active » Fixed
niklp’s picture

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 ;)

yched’s picture

Correct use is
return _phptemplate_callback('search_theme_form', array('form' => $form));
with template search_theme_form.tpl.php

johnalbin’s picture

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.

kdebaas’s picture

Title: sub-theme's search-theme-form.tpl is ignored » Hook names have to be valid php function names
Status: Fixed » Active

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:

  • Why does this kind of Views Theme Wizard output work in other themes? (a bit of an assumption though)
  • Why does it work when the path to the subtheme tpl.php file is included, like so: _phptemplate_callback('pathtosubtheme/views-list-MyView', $vars); hyphens and all?
johnalbin’s picture

Title: Hook names have to be valid php function names » Subtheme search-theme-form.tpl file only called when path from Zen folder is specified
Status: Active » Fixed

Why does this kind of Views Theme Wizard output work in other themes?

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.

Why does it work when the path to the subtheme tpl.php file is included, like so: _phptemplate_callback('pathtosubtheme/views-list-MyView', $vars); hyphens and all?

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.

niklp’s picture

...aaaand again, what's the "official" workaround for this Views bug, if there is one? Thanks! :)

kdebaas’s picture

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'));

johnalbin’s picture

Yep, Klass is correct.

niklp’s picture

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 :)

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

yan’s picture

Status: Closed (fixed) » Active

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. -->

marcvangend’s picture

Yan, in views_list_VIEWNAME, did you replace VIEWNAME with the actual name of your view?

yan’s picture

Yes I did, marcvangend.

johnalbin’s picture

Status: Active » Closed (fixed)

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! ;-)

ipwa’s picture

tracking this issue

johnalbin’s picture

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.

ipwa’s picture

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.