Closed (fixed)
Project:
Printer, email and PDF versions
Version:
6.x-1.12
Component:
Miscellaneous
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
24 Oct 2010 at 18:35 UTC
Updated:
2 Aug 2011 at 00:13 UTC
I'm theming a content type that contains various cck fields using a custom node template. Two of the fields in this content type are multi-value cck fields. For these, I'm using a template variable in the form of $FIELD_NAME_rendered (mentioned here: http://drupal.org/node/807330).
In the normal view of the node, all works well. However, for the print view, the selected values for multi-value checkbox fields are not visible. They simply disappear from the html. The 'Print' display settings for these fields are standard default values.
Any ideas for how to resolve or troubleshoot?
Comments
Comment #1
dave bruns commentedAny ideas anyone?
If I print_r on $node in the print template, I can see the values for the cck field in an array (seven items, because the cck field has seven possible check box values) but they don't appear in the print view of for this node.
The print-specific template is using $print['content'] to output the body content. Do I need to change this?
Happy to provide more info if that would be useful.
Comment #2
Pav-2 commentedThe way I approached this issue was to base my print template on a combination of most of my pate.tpl and print.tpl together. This worked fine and then I just trimmed it down leaving the stuff I wanted.
Hope this helps,
Pav
Comment #3
markdorisonI am experiencing this same issue. The rendered variables that are available to the themer in node.tpl are not available here. If you are trying to theme the node without using the $content variable, this is problematic.
Comment #4
Pav-2 commentedHi,
Have you seen these 3 top comments:
http://drupal.org/node/190173#customtemplate
It really helped me getting my head round all this. My problem was also enhanced by overlooked permissions on the cck field.
Hope this helps.
Comment #5
karens commentedThe basic problem here is that the print module calls print_preprocess_print_node(), which in turn directly calls template_preprocess_node(). This completely bypasses the normal theme system, it only uses whatever is in the core function. CCK adds these extra values in content_preprocess_node(), but that never gets invoked as this code is currently structured. Other modules implement hook_preprocess_node -- Views, Nodereference, the theme, and who knows how many others. As far as I can tell, none of these will get triggered.
At first I thought that was the problem, but there is a bigger problem. The print page does not use the theme system at all. The print.pages.inc file contains a function called '_print_var_generator' which creates the variables that are available in the print theme. That function creates a hard-coded list of variables, which is not going to pick up any variables added by content_preprocess_node even if that function was getting called. There seems to be no way in that code to add other variables, they just don't exist as values you can do anything with.
I don't know why the print themes were constructed this way or what the implications would be of doing this in a more standard way -- so that all the hooks get triggered normally.
Comment #6
karens commentedAfter more digging -- the node variables won't be available in the page. The *page* variables are there. $FIELD_NAME_rendered is a node variable. The place to grab node variables is in the node template, not the page template.
So I backed up to try to see what is available in the node template. But as far as I can tell, no node template ever gets invoked. The code indicates that I should be able to use templates like 'node-$type' or print_node_html.node-%type', so I tried that, but they never get invoked anywhere. I tried adding markers to all the node_WHATEVER templates I had in core and my theme but none of them get invoked in the creation of a printed page. I can't find any comments about trying to use custom node templates to tell why they won't work for me, so I can't tell if I'm doing something wrong or that is just broken. I did clear caches whenever trying to make changes to templates, but no love.
Comment #7
karens commented#1005290: print.tpl.php in theme folder not detected even after rebuilding theme registry. is another report that the node templates don't get invoked. #981952: Using hook_preprocess_node variables and #973838: Not getting variables from theme_preprocess_node are other reports that hook_node_preprocess functions don't get invoked. #954864: If Display Suite is present, let it handle print layout indicates that node_view() never gets invoked. So other people are having trouble finding any way to alter the default display of the node.
Comment #8
Pav-2 commentedTry placing it in print/ and see if this helps.
I've had it working for the print with no huge problems, my issue was theaming it for the pdf as I omited the fact that I had to create print_pdf.tpl.php (and place it in print - otherwise it didn't work as far as I remember - I think I found someone had the same problem - http://drupal.org/node/376668#comment-3917498).
The faq is pretty good and I think contains all you need to solve your problem just have a look. I can confirm that I was able to theme my templates the way I wanted but it was hard to get it going.
Comment #9
karens commentedIt does not call the node template. It *does* call the page template, which is what print_pdf.tpl.php is. The fact that you can theme something using a page template does not mean that the node template is getting used. If the node template is not used, it is impossible to pass node variables, which is the subject of this issue.
Comment #10
markdorisonComment #11
s_u_s_a_f_o_n commentedIn "print_[format].node-[type].tpl.php" theme file, I have used the variable "$variables", where You can access cck fields easily. It is not that elegant solution, but works well without big pain.
Comment #12
keva commenteds_u_s_a_f_o_n (#11), can you elaborate, or paste a snippet of example code?
thanks in advance
Comment #13
s_u_s_a_f_o_n commentedIn body of
print_html.node-[content_type].tpl.phptheme file i useprint $variables['print']['node']->field_info[0]['view'];where field_info is cck field. For the variable structure i have used
print '<pre>'.print_r($variables['print']).'</pre>';before.Comment #14
interestingaftermath commentedThis method worked fine for me. Thanks!
Comment #15
keva commentedthanks, s_u_s_a_f_o_n. That worked.
Comment #16
ericduran commentedMaybe I'm wrong, but this feels like a bug to me.
Comment #17
rconstantine commentedYeah, this is a bug. Using conditional_fields module, no field that is triggered by another shows up in the print view. That's a big problem for me. Also, anyone using a CCK multigroup is unable to render the items individually using the method from #11, so forget about making the print version custom compared to your normal page view.
I'll be trying to figure something out because I need those fields to print!!!
Comment #18
rconstantine commented@KarenS - Thanks for identifying some of the functions involved. As you see it, how does a 'normal' module work with the theme layer? I'm afraid that is my weakest area in Drupal. I'll be reading a lot today it looks like. :(
Comment #19
rconstantine commentedSeems that the conditional_fields module was to blame. I'm not sure why, but in print mode, the 'view' operation in the hook_nodeapi function is filtering out all of the conditional fields regardless of whether they should show or not. For now, I do a check to see if $node->printing is TRUE and simply return. It seems like CCK is correctly hiding the fields that should be hidden all on its own. So I'm not sure this operation is even necessary.
BTW, I'm using the latest dev version and found a bug I'll post in another issue.
Comment #20
candelas commentedthanks s_u_s_a_f_o_n !!!
i was going crazy!!! :)
Comment #21
jcnventuraHi,
I've just applied #1062634: "hook_alter_theme_registry" ignores theme level preprocess functions, which adds calls to all the defined hook_preprocess_node() functions.
After that, I tested it and indeed the rendered CCK fields variables are now available.. However as KarenS has also stated in this thread.. The print.tpl.php is in reality a page.tpl.php so don't expect to have the node variables to be available there. The module calls your existing node.tpl.php files, so you probably don't need to do anything new.
If you need access to the node contents at page level, the suggestion in #13 applies neatly.