Drupal: Argument Handling in Views
Add a textarea where we can put content to show up in a block beside a node
I want a column called 'adcolumn' which is hand-filled to show stuff relating to pages. A 1-1 relationship.
-
Create the Field
Enable Views and CCK and Text field
- admin/content/types/page . Add Field. Text. Called adcolumn (10 rows). Text processing: Filtered text . (we'll come back later after testing)
- Create/Edit a node page. Cool, the new field appears. Put something in it and save to look at.
-
Create the Block
Add a view. admin/build/views/add . Called adcolumn also if you like, it's not important and they don't conflict.
- Description: "Block that shows up beside the node". No page view. No Menu. Yes, Provide Block.
- View Type: Table or List view (Neither are optimal, I'm looking into that)
Title: optional
Nodes per Block: 1 I guess. Doesn't make a difference.
No more link, no header or footer or empty text (for me). - Add Field: Text: adcolumn. Press [Add Field].
No sorting etc options need to be changed. (Label:blank, Handler:Group, option:default, Sortable:no, Default Sort:none) - Here's the fun:
Add Argument: Node: ID
Default: Empty Text, Title: blank, Option: equal, Wildcard:blank, Wildcard Sub: blank - As in the instructions above, add code
Argument Handling Code
if (arg(0) == 'node' && is_numeric(arg(1))) {
return array(arg(1));
}NO PHP TAGS
- ... and save.
Almost there... -
Enable, theme, layout
Visit admin/build/block and shift the new block into a sidebar or something.
Have a look at the page you added side content to before.
It should start showing up! - Depending on your theme, you may also be seeing it repeated in your page as well. That's the normal behavior for CCK fields.
Turn it off by visiting [Administer - Content Management - Content Types - Page] and clicking the "Display Fields" tab. - Set all values for 'adcolumn' to Hidden and submit.
- Go back to your page. phew Cool!
It's all cool once you know what you are doing, but I got sidetracked trying to grok argument handling.
Source: http://drupal.org/node/83415#comment-244727