Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
First of all, I'm using drupal 6.
I'm creating one template and I need to write the path of the files from node attachments.
The Content Template module shows something like "$node->files[1290]->filepath" but the id (1290) is unique and not related to the node id.
I tried many drupal 5 and 4.7 solutions found in this site but none did work.
Comments
Comment #1
dman CreditAttribution: dman commentedThe id will be either the file id, or the file revision id, depending on version or something...
But who cares?
You'll probably be wanting something like:
(untested)
Comment #2
jrglasgow CreditAttribution: jrglasgow commentedif you could post the section of your body variables that pertains to the files, I would help us help you. Please post it in
<code>
tagsComment #3
patrickmedina CreditAttribution: patrickmedina commentedDman, thanks for your answer, but your code didn't work :(
This is the output of the body variables in content template:
Comment #4
patrickmedina CreditAttribution: patrickmedina commentedjrglasgow?
Comment #5
jrglasgow CreditAttribution: jrglasgow commenteduse code like this:
the l function will return a link based on the path, the url function will just return a URL, not the whole link.
Comment #6
sampeckham CreditAttribution: sampeckham commentedGreat I was trying to work this out too, it's not obvious! However, can you tell me how I might adjust this for just one node with one attachment. Is there a quick way to just grab the $key value, without the for loop?
Thanks
s
Comment #7
jrglasgow CreditAttribution: jrglasgow commentedyou could use array_keys()
this is pseudo code, it has not been tested
Comment #8
dman CreditAttribution: dman commentedKeep the foreach. It's more robust code, as I would not trust the index being zero, or array_pop returning right in the case of no files.
using a foreach will loop over zero, one, or more the same way.
If it bothers you, just break; out of the first successful loop.
Comment #9
sampeckham CreditAttribution: sampeckham commentedThanks for these responses, I have stuck with the for loop and that works fine in one case.
But I do have a question that relates to this, and have thrown it to the forums to avoid hijacking this thread: http://drupal.org/node/327085