I just started using this module. I'm using Content Template to make a custom template, and also the views_attach module, for one of my node types. (The view I'm attaching is a list of noderefs created by users.)

In my template, I use this code to show the attached view in the page content:

print $node->content['attachedviewname_node_content_1']['#value'];

The printer-friendly version handles everything else in my custom template just fine, but I can't get the attached view to show up there....any way to make it work?

Thanks in advance!

Comments

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

Have you tried to add that line to the print.tpl.php template??

João

Lanae’s picture

Version: 6.x-1.9 » 6.x-1.10

Yes, I tried adding it to the module's print.tpl.php file, and also tried it adding this before it, as suggested in your documentation:

$node = $print['node'];

I also tried to create a print.node-type.tpl.php in the theme directory, using my code from the Content Template that prints the view. This is what I'd prefer since it's only the one node type that uses the attached view. I tried clearing Drupal's cached data and going to the theme config page, but this didn't change the PF page either - still no attached view.

Here is what my print.tpl.php (in the module's directory) now looks like:

<?php
// $Id: print.tpl.php,v 1.8.2.15 2009/07/09 12:00:52 jcnventura Exp $

/**
 * @file
 * Default print module template
 *
 * @ingroup print
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $print['language']; ?>" xml:lang="<?php print $print['language']; ?>"
>
  <head>
    <?php print $print['head']; ?>
    <title><?php print $print['title']; ?></title>
    <?php print $print['scripts']; ?>
    <?php print $print['robots_meta']; ?>
    <?php print $print['base_href']; ?>
    <?php print $print['favicon']; ?>
    <?php print $print['css']; ?>
  </head>
  <body<?php print $print['sendtoprinter']; ?>>
    <?php if (!empty($print['message'])) {
      print '<div class="print-message">'. $print['message'] .'</div><p />';
    } ?>
    <div class="print-logo"><?php print $print['logo']; ?></div>
    <div class="print-site_name"><?php print $print['site_name']; ?></div>
    <p />
    <div class="print-breadcrumb"><?php print $print['breadcrumb']; ?></div>
    <hr class="print-hr" />
    <h1 class="print-title"><?php print $print['title']; ?></h1>
    <div class="print-submitted"><?php print $print['submitted']; ?></div>
    <div class="print-created"><?php print $print['created']; ?></div>
    <div class="print-content"><?php print $print['content']; ?></div>
<?php
$node = $print['node'];
?>
<div class="print_content"><?php print $node->content['attachedviewname_node_content_1']['#value']; ?></div>
    <div class="print-taxonomy"><?php print $print['taxonomy']; ?></div>
    <div class="print-footer"><?php print $print['footer_message']; ?></div>
    <hr class="print-hr" />
    <div class="print-source_url"><?php print $print['source_url']; ?></div>
    <div class="print-links"><?php print $print['pfp_links']; ?></div>
  </body>
</html>

(also, I clicked the wrong version first time, sorry...I'm using version 6.x-1.10.)

Thanks again for your help!

Lanae’s picture

Status: Postponed (maintainer needs more info) » Active

So...should the above have worked, or am I doing something wrong?

tfrech’s picture

Did you get anywhere with this problem yet? I have the exact same situation. I think the print module doesn't include the attached views in its node object. I can print_r the $print object and I can find:

[resume_experience_node_content_1] => 
Array (
[label] => Work Experience 
[description] => Attached view: resume_experience - node_content_1 
[weight] => 7
[configure] => Configure
)

but if I print_r the node object from the normal node view I get the same thing but I also get:

[resume_experience_node_content_1] => 
Array (
[#value] => ...the view contents are displayed here
[#weight] => 7
[#title] => 
[#description] => 
[#printed] => 1
)
tfrech’s picture

I would be very interested to know if anyone has resolved this problem. I have put my project on hold because of this issue but I will need to get back to it soon. Any ideas, even module hacks would be appreciated.

tfrech’s picture

Eureka!
Here is what you need to do:

At the top of your print template file, put this

$node=$print['node'];
$node->content["yourviewname_yourdisplayid"]["#value"]=views_embed_view("yourviewname","yourdisplayid",$node->nid);

yourviewname is the name of the view that you are loading
yourdisplayid is the name of the specific display which is usually "node_content_1"

You should do this for each of the views that you are embedding into the node.

jcnventura’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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