File attachments in Blocks? - drupal

Whats the best way to have file attachments in blocks like you can with nodes? Is this possible with an existing module?

If your attachments are CCK File fields, you can use CCK Blocks module for this purpose.

I think the best course of action, is to create a block and then create a view of the node with a block display. With a bit of work you could automate the process, and don't publish the node if you prefer it not being viewable.
You could create a base view in the views UI and export it, the only thing you would need to configure is the node id.
That is one way of doing this, that doesn't require too much work, and utilize a lot of modules you probably already have enabled for the site.

Use views, create a block display and set it to display file attachments for the specific node type. Set the argument to node ID by providing a default argument and telling to fetch the node ID from the URL.
Bam!

Related

Drupal - Show content on specific page

Am I able to add the following field to a content type, so that each piece of content I create can be conditioned to a page?
Or is there a module to extend Publishing Options, where by it adds all the pages I have created (just like 'Promote to Front Page')?
If not, why is no one doing this? As a new user to Drupal this seems like it would be a handy operation. (I have already tried this module but it doesn't achieve the results I'm after).
If none of these solutions are available, what would be the best alternative way of doing this?
I've posted this question on Stack Exchange for Drupal but I need a quick answer and there seems to be a bigger community here :D
You should use Context. With Context, you'll be able to manage contextual conditions and reactions for your drupal like Regions.
Have you used Views? it is one of the most common used drupal modules. It doesn't extend publishing options directly but it does replace it in a way. You can say by example put a list of al content-types: your_own_Content_type that have the publishing options of promoted to front-page. then sort them by title, date, what ever you like.
you could also create only one view and create multiple blocks out of it. you have to understand the logic of drupal: if you want different blocks on different pages, you have to create the different pages AND different blocks
create the view for one type of content-type and make one block out of it. put this block on the desired page. All your other blocks are made with the same view, just adjust a condition in your view and create a new block out of it. You should also put all your blocks in the same region, and set the to the right pages
here you can find a lot of documentation if you run into any problems... drupal.org/project/views
Views is the best at creating a slideshow of images or any type of data on your site.
Used in combination with nodequeue it might offer near or the full functionality you are trying to achieve (check this out ... and this too) - but I don't understand your question entirely.
By my opinion Views is too complicated task for much simple request.
There is a few ideas for solution:
Easy way - You can create a specific template file or add some if statments to the node.tpl.php(specific tpl better)
For minor changes - Create a new context with "path" filter and "theme html" reaction, than hide the field by the css
Best but complicated(large usages) - create a new "view mode" and implement the display by new "hook_menu".
~ Almog

How to create a node reference field using the CCK API?

We're currently building a module which automatically create content type, which allow to quickly install content types on any Drupal platform, without having to manually create hundred of content types and fields. In our previous versions, we were manually creating node reference fields and it works great. Now, we want to create it using our module since we have to add those content types and fields on dozen of platforms already under production; creating manually the fields would be a crazy idea. Do we have to use the node reference API? We are close to being able create it but, in VIEWS, the node reference fields do not appears. It seems we missed something. We're trying to check in the CCK php files to understand how the CCK API is used (if we can create it in a form then, for sure, we can code it). Any idea? Which API and functions should we use? I would like to know the proper method on how to do this.
You should use features rather than write code to create content types. Take a site w/ all the types you need, export them to a feature, integrate that with your module, easy as pie!

Drupal: how to add pdf links to a block?

I've some blocks in my Drupal website with some text.
I need to other some links in the text, to pdfs (and upload them from back-end).
Can I add some upload fields to the block pages, and link them from the text ?
thanks
Check out the Insert module, which allows you to upload files to a FileField and then easily link to them from within the node body.
I usually just end up attaching them to a node and then linking them manually. Not the answer you were probably looking for, but it works.
If you have views module available you can create a view that lists the pdfs attached to a particular node, using the node id (nid) as an argument, or use more complicated arguments if you want, as long as the fields displayed in the view are the the filefields you used for your pdf you can get pretty creative with how the pdfs are organized.
It's somewhat tricky to get arguments into views blocks but it's certainly possible, using panels, or using other tricks. More info on that:
here: http://drupal.org/node/150482
here: http://drupal.org/node/695124
http://drupal.org/node/161867#comment-1086587
Might not actually help you, but the D7 version of http://drupal.org/project/block_api creates fieldable blocks, which means that you can attach any type of fields to created blocks.
For D6, the solution is more complex I guess. You could create a separate content type, attach the files there (by using Inline, FileField, ...). Then, either write a custom module that exposes a block for each node of that type and then renders the node in those blocks or use Views to create a view of a single node. Using views would be a bit overkill I guess but should be relatively fast if you can use caching..

Fundamental understanding of how Views and Pathauto work together

I am having fundamental problems understanding when to use a pathauto rule, and when to use a views page path. I have several custom content types, and I am using blocks to display certain parts of nodes on certain paths. Then I use a views page to display the main node on a path.
When I do this, I can't use pathauto, as it overrides the paths I set in views. Eg.. If I set up a views page path of "location/%", and set a pathauto rule for Location content types of "location/[title-raw]", when I browse to mysite.com/location/mylocation pathauto wins, and simply displays the full node. And if I can't use pathauto, I can't add arguments on my blocks, because Drupal doesn't understand what it's looking at anymore! Arrrg!
I've tried installing Util, and altering the weight of the modules, but that didn't work. But I shouldn't have to do anything crazy like alter module weights, right? There must be some basic flaw in my thinking.
How do you keep your paths and content organized?
Help me flow like water, help me become the cup.
Ok, I've solved my problem. The actual question I should have asked was:
How do you display a single node?
I was basically using Views to style a single node. Of course, this is not what Views is designed for. See others with similar problems:
http://drupal.org/node/400400http://drupal.org/node/316907
My solution:
Let pathauto do all the work.
Add, arrange and style your content as desired at the theme
layer.
In more words: remove views page view, taking the corresponding location/% path with it. Set up your pathauto rules the way you want. Copy node.tpl.php to your theme directory. Duplicate that file and rename it node-[type].tpl.php. Alter node-[type].tpl.php instead of setting up rules in Views.
For more help theming a specific CCK content type see:
http://drupal.org/node/266817
Don't forget!
When using phptemplate node-[type].tpl.php suggestions, there must also be an original node.tpl.php template present in your theme directory or the template suggestion is ignored.
Hope that helps someone else!
Right. The % is a views argument, views superceeds URL aliasing every time. Drupal expects anything after location/ to be the passed in value you are looking for which is why it doesn't understand, or you aren't getting the result you want.
Why are you using views though to control a node view? If you are adding blocks to a view, you should be able to assemble the data in views, and use the Block admin to set the path it displays on (location*).
In general is a good practice to theme the node page and do not let views generate additional urls. It can lead to several problems, as many modules link to the standard node page. Use views to generate listings that links to the node page.
You can also theme a node page without coding, using context or display suite modules.
Just let pathauto do the work, a good idea is to generate the alias based on the menu hierarchy, to have a consistent url scheme. Check out this question: Drupal 7:Pathauto patterns from menu structure hierarchy

Drupal views: Allowing users to choose sort criteria on node display

I have some nodes I am displaying in a view. They are displayed as nodes, unformatted. I would like the user to be able to choose from some predefined sort criteria ( via drop down list or similar).
So they could pick recently active, most commented, newest, etc., and re-query for new results.
Its easy with tables because you can make the labels clickable, but I do not know how to have similar functionality with a raw node preview display.
Just a thought, from me to me, and for anyone else who may be trying to do this.
An easy, sleezy option would be to just add another page view for each of the required sorts, and provide a link to these other views in the header of each of the pages.
This could also allow for (easier) linking to the individual sorts, so say if you have a sidebar block displaying recently commented nodes, you could adjust the .tpl.php of the block to have the title link to the view displaying the full set of recently commented nodes.
also im pretty sure there should be a way to do this with arguments, but i dont know how
Views 3 supports exposing sort order (just like you can expose filters)
Select the sort order (e.g. add sort by node creation date, then click on the settings for that), you should be able to expose the sort order to the end user. This is just like clicking on the settings for a filter and then choosing to expose it.
Standard views isn't going to support this, so IMO you're best off implementing a custom solution using just a plain old view and this jQuery plugin. You can either do this at the theme layer (the same way as any other JS in a theme) or a custom module (via drupal_add_js() to add the plugin and your bit of custom code). Either way will work, although the custom module has the obvious benefit of being theme independent (and thus more portable).
If you go the custom module route, please consider releasing it as a contrib module on http://drupal.org.

Resources