0

i would to theme a specific webform page and i achieve this with devel themer help but i find it not logical. Usually i use ID to specify a template for a page, node or other element. Then in my case i use the node-419.tpl for my node 419.normal For my page it's a bit more complicated because this the hierarchical applied template :

page-infos-profil-élève.tpl.php < page-webform.tpl.php < page-node-419.tpl.php < page-node.tpl.php < page.tpl.php

so why a template called page-webform-419.tpl.php doesn't work instead of page-infos-profil-élève.tpl.php ? Could i do this with php in my template.php file ? if yes how ?

thanks

2 Answers 2

2

This depends on your template suggestions.

Open template.php in your theme folder, and look for a function named YOURTHEME_preprocess_page, if it does not exist, create it like:

function YOURTHEMENAME_preprocess_page(&$vars)
{
    debug($vars['theme_hook_suggestions']);
}

And see what suggestions (and in what order) you have.

EDIT: this is a preprocess function I used in a theme of mine, in theme's template.php:

/**
 * Implementation of hook_preprocess_page()
 * @param $vars
 */
function THEMENAME_preprocess_page(&$vars){
    // I like to store templates in different folders inside the theme dir
    foreach($vars['theme_hook_suggestions'] AS $i => $ths){
        $vars['theme_hook_suggestions'][$i] = 'pages/' . $ths;
    }
}
/**/

In your case, simply do debug($vars, 'preprocess page vars!'); to see what variables you have a dispostion (please note: flush the cache after editing/creating this kind of function, and the output of debug($vars) can be very big!) and then add your template suggestion.

Maybe this can help: theming d7 webforms

15
  • My suggestions are provided by devel themer module..do your function give me more infos ?
    – user8753
    Sep 24, 2013 at 14:27
  • Ah ok, devel module is probably more accurate.. have you tryed to clear (flush) the cache? A lot of problems like this one can be solved just clearing the cache.
    – Strae
    Sep 24, 2013 at 15:56
  • yes i clear cache all the time i modify a tpl or css...but if devel doesn't suggest page-webform-419.tpl.php i think it's an issue in my template.php, because i have a code to get template suggestion like page-[content-type] into...?
    – user8753
    Sep 25, 2013 at 7:30
  • Wait, devel does or does not suggest page-webform-419.tpl.php ? If not, follow my advice; In the preprocess page you can add suggestions, just identify when is the page that you need and then add the suggestion ;)
    – Strae
    Sep 25, 2013 at 11:03
  • exact, but i get an error with : function Cyrano_PF_preprocess(&$vars, $hook) { switch($hook) { case 'page' : if (arg(0) == 'node') { $vars['template_files'][] = 'page-' . $vars['node']->type; } break; } debug($vars['theme_hook_suggestions']); }
    – user8753
    Sep 25, 2013 at 11:37
0

yes i figure it out like this:

function cyrano_pf_preprocess(&$vars, $hook)
{
    switch($hook)
  {
      case 'page' :
      if (arg(0) == 'node')
      {
        $vars['template_files'][]  = 'page-' . $vars['node']->type;
        $vars['template_files'][] = "page-" . $vars['node']->type . "-" . $vars['node']->nid;

      }
      break;

  }

}

with the help of https://stackoverflow.com/questions/8956045/how-can-i-customize-a-specific-node-in-drupal-6-when-a-custom-template-has-alrea , then i get this choice for now (from devel) :

Candidate template files:
page-pentreprise.tpl.php < page-webform-420.tpl.php < page-webform.tpl.php < page-node-420.tpl.php < page-node.tpl.php < page.tpl.php

now, i can use a tpl file like page-webform-999.tpl to theme a specific webform page..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.