[Solved] Theming a file and location

Events happening in the community are now at Drupal community events on www.drupal.org.
bstoppel's picture

Hi All.

I've been beating my head against the keyboard for quite a while now (days and days) trying to solve two problems. I am hoping some insight will help me save my sanity.

The first problem is with getting the path to an uploaded file.
The second problem is with getting the data out of a "location."

My set up is Drupal 6 with Views 2, CCK, and Location CCK. Everything is up-to-date.

I've set up a content type that allows uploading of an image and the entry of a location. Corresponding to this, I've set up a view (Row Style: Fields) to pull the content for the file as "path to file" and the individual location information. The file path works great in live preview, but not in my template file override (views-view-files--my-content-type.tpl.php). In my file override, I get the fid. I don't know how to get to the actual file path. The location is failing in both live preview and my template override. The location appears to be working fine when I visit the node.

Any help would be greatly appreciated.

Brett

Comments

bump

bstoppel's picture

I have tried a few more things to no avail. I tried switching to Row Style: Node, but don't get the granularity that I need from it.

Can anyone provide insight into either problem that I am experiencing?

Thanks.

Getting the file path solved

bstoppel's picture

I've solved the first one thanks mostly to this post about the lightbox2 project, http://drupal.org/node/328095 .

Basically, the function field_file_load() does the work. Pass it an fid and it will load an array with filepath as well as other data. I believe CCK FileField has to be enabled for this to work. I haven't disabled it so I could be wrong.

Here is my code (more or less):

<?php  $image = field_file_load($fields['logo_fid']->raw); ?>
<img src="<?php echo $image['filepath']; ?>" alt="<?php echo $fields['title']->content; ?>"/>

BTW logo_fid is a CCK defined field.

Now if I could just figure out the locations problem...

Theming Location CCK with Views solved

bstoppel's picture

I figured out how to get data out of Location CCK using Views2. The key is using a relationship. I tried it before but didn't realize the second set up setting up a relationship. Here is great screencast tutorial on using Views2 relationships, http://drewish.com/node/127.

Quick overview of my setup.

  1. Create custom content type using CCK
  2. Add a custom field of Type: Location
  3. Create a new View with Row Style: Fields
  4. Add Relationship to your custom field
  5. Add field for each part of the location assigning the previously created relationship.
  6. Edit/create file views-view-fields--CONTENT-TYPE.tpl.php similar to my previous post.

That should do it.

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: