I am using webform, and am trying to create a printer friendly version of the webform confirmation page.

The webform node is 45 and the node type according to the database is webform

I'm having a problem getting the custom print template suggestion to work in the themes directory.

If I try (in the themes directory)
print.tpl.php - works
print--html.tpl.php - works

However, nothing below works (it is just ignored and the modules default print.tpl.php fires):
print--node--webform.tpl.php
print--node--webform--45.tpl.php
print--html--node--webform.tpl.php
print--html--node--webform--45.tpl.php

I'm not sure where to go from here.

Comments

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

Did you clear the caches everytime you renamed the files?

jmoyles’s picture

Just tried that - no change in behavior

jcnventura’s picture

Sorry, I only read your original post in detail now.. The webform confirmation page is not a node, and thus can't be themed like that..
The page at yoursite.com/node/45 (which would be the unfilled webform), is indeed a node and will should obey the above templates.

However, the confirmation page is something generated by the webform module (not a node) and can only be 'themed' using one of the two templates which you've already seen working.

If you really need to handle a webform confimation page differently than the rest, you'll need to modify the print[--html].tpl.php file to detect and handle that case separate from the normal pages.

jmoyles’s picture

Understood - thanks for looking into this as it's really not a "you" problem, but instead a side effect of Webforms.

Quick Q, and this may be answered elsewhere - is there a hook (preprocess or otherwise) that you are aware of that I can modify to catch this case and add in appropriate template suggestion in the print module and/or core? Again, not your job to teach me Drupal, but it looks like you've done some work in the template suggestion arena.

jcnventura’s picture

Project: Printer, email and PDF versions » Webform
Version: 7.x-2.x-dev » 7.x-4.x-dev

Better ask the webform maintainer if he provided any such hook.

jmoyles’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Will do, thanks J.

Closing until I figure out whether or not I need help to execute on this.

jmoyles’s picture

FYI for anyone stumbling across this thread:

I didn't see anything that would allow me to catch and act on a print template suggestion in webforms, so I did as jcnventura recommended and turned my theme print.tpl.php into a template broker for webforms.

jmoyles’s picture

Dug around a little more. Came up with this solution to allow print template suggestions for non standard nodes (like the webform confirmation page).

By using THEME_process_HOOK, I can fire actions after function print_preprocess_print (print.pages.inc) from the print module (this is worth a read: http://api.drupal.org/api/drupal/includes%21theme.inc/function/theme/7 )

Armed with this knowledge, I created the following two new functions in the theme template.tpl.php file (note this is for the site I am working on, and may not work in all circumstances):

// Function really stolen from another module of mine, but will work fine here
function custom_functions_get_node_type($nid) {
	$return = NULL;
	
	$nodeLoad = node_load($nid);
	
	if(isset($nodeLoad->type))
	{
		$return = $nodeLoad->type;
	}
	
  return $return;
}

function THEME_process_print(&$variables)
{
	if(isset($variables['format']))
	{
		// Printing
		if(!isset($variables['node']->nid))
		{
			// Non standard node (like webform).  Standard nodes will have the proper print template suggestions
			if(isset($variables['node']->path))
			{
				// Has a path, extract
				$paths = explode('/', $variables['node']->path);
				$printNodeId = $paths[1];	// $nid
				if(count($paths >= 3))
				{
					// There is a node action
					$printNodeAction = $paths[2];	// like webform confirmation "done"
				}
				
				if(isset($printNodeId))
				{
					// have node ID, get node Type
					$printNodeType = custom_functions_get_node_type($printNodeId);

					if(isset($printNodeType))
					{
						// Have id and type, construct a print page template names in the following formats:
						//      print--format--node--content-type--nodeid--nodeaction.tpl.php (if nodeaction, custom for webform)
						//		OR
						// * 1. print--format--node--content-type--nodeid.tpl.php
						//
						// * 2. print--format--node--content-type.tpl.php
						//
						//      print--node--content-type--nodeid--nodeaction.tpl.php (if nodeaction, custom for webform)
						//		or
						// * 4. print--node--content-type--nodeid.tpl.php
						//
						// * 5. print--node--content-type.tpl.php
						if(!empty($printNodeAction))
						{
							$variables['theme_hook_suggestions'][] = 'print__' . $variables['format'] . '__node__' . $printNodeType . '__' . $printNodeId . '__' . $printNodeAction;
						}
						else
						{
							$variables['theme_hook_suggestions'][] = 'print__' . $variables['format'] . '__node__' . $printNodeType . '__' . $printNodeId;
						}
						$variables['theme_hook_suggestions'][] = 'print__' . $variables['format'] . '__node__' . $printNodeType;
				
						if(!empty($printNodeAction))
						{
							$variables['theme_hook_suggestions'][] = 'print__node__' . $printNodeType . '__' . $printNodeId . '__' . $printNodeAction;
						}
						else
						{
							$variables['theme_hook_suggestions'][] = 'print__node__' . $printNodeType . '__' . $printNodeId;
						}
						$variables['theme_hook_suggestions'][] = 'print__node__' . $printNodeType;
					}
				}
			}
		}
	}
}
jmoyles’s picture

For above, replace THEME with your theme, also you don't need to do anything to have this fire - it will process automatically.

Tronux’s picture

For confirmation pages: webform-confirmation-590.tpl.php
Change the 590 to your specifiq webform nid.