Is it possible to reference custom region content via the print template files?

So for example, for my custom Drupal theme I have defined the following regions in its info file:

regions[frontright] = front right
regions[frontleft] = front left

These are printed within one of my page templates as "print $frontright" and "print $frontleft" respectively in the places I want.
Trying to print these variables within the print.tpl.php file doesn't work. Do I need to do something for the print template to recognise these custom region variables?

Many thanks in advance.

Comments

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

Hi,

I don't modify my themes myself, so I am not familiar with what you're saying. The generic answer to your problem is: the print module is designed to not depend on any theme. Specifically the output of the print module is what you would see for each node if you decided to switch your theme to ANY non-modified module.

Your modification goes smack against this principle, so the solution will be far from nice... Specifically, forget about any variable that you have in your theme templates. Now, if you really need something from a specific theme, you are able to place custom php code in the print.tpl.php template. In this case, you would need to duplicate the calls that Drupal makes to your theme so that at one point you have access to the regions that you have set up. What those calls are, I don't know. I hope it's a bit short of duplicating the core Drupal code inside the print.tpl.php.

João

fgasking’s picture

Basically drupal has the concept of its regions defined in a template's .info file, where you have also $content defined and can drop blocks and various things into it ($content is a default region also to all pages). The print.tpl.php references the content region, and this is mainly because it is defined within the print.pages file.

However, I have a front page layout which adds two custom regions to the page via the .info file .. and so I need to create a print.tpl.php file for that front page which picks up those two custom regions as well as the content region. Within my standard template file for the front page, this is just a case of "print $customregionname".

Sorry if my explanations are quite bad ... there's probably aspects i'm not explaining very well!
Sounds like this is going to be problematic :)

fgasking’s picture

Something else i've just noticed, but i've set up a view block which pulls out 3 most recent posts . I've told the block to display within the $content area region.

Although my written content above on the page is displaying in print view with no problem, the view block isn't showing at all.

jcnventura’s picture

The print.tpl.php references the content region because the original module author chose to call it that.. The contents of that variable are set by the following line in print.pages.inc

$print["content"] = $node->body;

It might have been a better idea to call it $print['body'], but that's not going to change now.

Repeating a bit what I am trying to say. The print module does not know the current theme. If your regions are defined in your current theme, then they are simply not accessible. It is possible that the output of those regions are being rendered in the print page however (there's too much going on inside the call to drupal_render() that creates the $node->body).

So my question to you is; are the contents of those regions being shown in the print page, or not? If they are, you should be able to cut and paste them from the page via preg_match and preg_replaces, as long as you have uniquely identifiable div's around the contents in those regions.. If they are not being rendered at all, that's another (very ugly) story..

João

jcnventura’s picture

Regarding the blocks issue, see this #268763: Add designated content blocks to print friendly pages, which includes an explanation on why it is happening and a solution to it.

João

fgasking’s picture

Ah, got you! ... thanks for the blocks issue, that's helped a lot.

Really great module btw, thank you!

jcnventura’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

No further comments in two weeks, closing the issue.

João