Hi,
what is the best code to use to display attached node files ? In particular if you have several files for a single node ?
Cordially,
Brakkar
Hi,
what is the best code to use to display attached node files ? In particular if you have several files for a single node ?
Cordially,
Brakkar
Comments
Comment #1
Robardi56 commentedIs there a way to display the attached file box just like for regualar pages ?
Brakkar
Comment #2
Robardi56 commentedSo does anyone know how to have the regular attached files box to display just like for any node when you don't use contemplate ?
Cordially,
Brakkar
Comment #3
jjeff commentedThe ConTemplate module lists all of the attributes of the node object during the view phase of hook_nodeapi.
There are lots of modules "out there" that add information to the $node->body, but DO NOT add any information to the $node itself. For instance, IMO there should be $node->event_view for the information that normally gets prepended to $node->body. In this case the file listing information gets appended to the end.
You can create a patch for most modules by finding the module's implementation of hook_nodeapi (example event_nodeapi()) and finding a line that looks something like this:
$node->body .= $eventstuff;or maybe:
$node->body = $eventstuff . $node->body;and inserting a line something like this:
$node->eventstuff = $eventstuff;just before it.
This way the $eventstuff will be available to ConTemplate separate from the body. It will show up in the listing within the template editing page and you can add it without having to call any special theme functions.
If you write these functions for these modules, PLEASE SUBMIT THEM as an issue for that module. This is the reason that ConTemplate is difficult to use with these modules.
I've looked at the hook_nodeapi() for upload.module and If you're concerned about hacking a module, it looks like you can also call the theme function directly from your content template like this:
print theme('upload_attachments', $files);(untested)Good luck!
Comment #4
Robardi56 commentedThank you very much Jeff.
Just tested your code inside the body template for a cck node type, and it displays correctly the attached file box ^^
Brakkar
Comment #5
(not verified) commentedComment #6
seanberto commentedI hate to open this back up, but I am using filemanager.module and attachments.module in place of upload.module. So, the last code snippet doesn't work for me.
Any advice? I tried the following theme call:
print theme('attachments', $node);But that didn't seem to work.
-sean
Comment #7
seanberto commentedHere's another way to do this, if you are using the attachment and filemanager modules instead of the core upload module.
http://drupal.org/node/63114
Comment #8
hectorplus commentedI have spent several hours trying to figure out how to display attached images into the node body.
Here's the code i inserted in the body field when using the contemplate module with the upload module.
<img src="<?php print $node->files[67]->filepath ?>">It displays the image but just for one node. Looks like the [76] is specific to one node. So when i create another node and attach an image, the image is not displayed.
Any ideas or guidance? Thanks.
Comment #9
Prodigyx commentedUse this:
Comment #10
hectorplus commentedThanks for that snippet, i make a bit of changes to this code from print pega_filepath($node); to print get_filepath($node); So far so good.
I am not good at php yet, so how do you include the code into an image code, like:
<img src="<?php ... ?" />Thanks for your help.
Comment #11
gsquirrelThis is for anyone else having this problem - i did finally get contemplate to display the right file for the right node using this code in the template:
This was on a 4.7.x site but might work with others too. I couldn't get the other suggestions to work (one seemed to crash contemplate completely!) so thought this may be of use to someone..
Comment #12
kristi wachter commentedIn 5.0, using Contemplate 5.x-1.3, I've had success with
<?php print $node->content['files']['#value'] ?>which appears in the Body Variables area on the edit page for the template I was building.
Comment #13
jjeff commentedYes. This makes sense. For Drupal 5 use the information in the $node->content array.
Marking this issue as "by design"
Comment #14
smoothdzion commentedYeah this totally worked for me. Man was it hard to find anything about this. I'm on 5 and replacing the pega with get worked perfect. Thanks. This is why open source is so much better than that "small"soft type of stuff.
Comment #15
jaclayton commentedWorked perfectly. Thanks!
Comment #16
crutch commentedsubscribe