Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a node link directly to its file contents in DRUPAL 6?

I have a menu item called "Products" which when clicked displays all nodes created by the "product" content type. Every "product" node has a file attachment field with a file attached.

If I click on a "product" node, it takes me to the node as expected and I can see all the fields on the node, including the PDF field:

enter image description here

I want to hover over the "Products" menu link, then see the different products as a dropdown in the menu and when a product is clicked I want it to NOT go to the node, but rather open the PDF attached to the node So instead of showing e.g /product/african-decor ... it must go to product/african_decor.pdf which is attached to the node:

enter image description here

like image 257
Granwille Avatar asked Oct 29 '15 07:10

Granwille


2 Answers

There are a couple of ways this can be achieved.


You can use the Menu Token module which allows you to use various fields in your menu paths. When building the token pattern you may need to create an absolute URL using the [site-url] token.

Also make sure the uses tokens checkbox is ticked.


This way is slightly less elegant.

Assuming you don't want to actually visit the product content type and will always download the PDF, you can overwrite the template for the product content type and redirect to the PDF URL.

You'd need to create

node--product.tpl.php

And replace the contents with

header("Location: " . $pdf_field);

// $pdf_field might be $node->field_pdf[0]['value'];
like image 108
Ben Swinburne Avatar answered Nov 02 '22 01:11

Ben Swinburne


You can implemement hook_taxonomy_menu_path with a custom module an override the base based on the nodes associated with the term. In the callback, return the path of the attachment in the node.

  • Given the fact that every term only has one node
  • Given the fact that every node has only one attachment
like image 30
Steff Avatar answered Nov 02 '22 02:11

Steff