Drupal: Argument Handling in Views

I want a column called ‘adcolumn’ which is hand-filled to show stuff relating to pages. A 1-1 relationship.

  1. Create the Field

    Enable Views and CCK and Text field

  2. admin/content/types/page . Add Field. Text. Called adcolumn (10 rows). Text processing: Filtered text . (we’ll come back later after testing)
  3. Create/Edit a node page. Cool, the new field appears. Put something in it and save to look at.
  4. 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.

  5. Description: “Block that shows up beside the node”. No page view. No Menu. Yes, Provide Block.
  6. 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).
  7. 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)
  8. Here’s the fun:
    Add Argument: Node: ID
    Default: Empty Text, Title: blank, Option: equal, Wildcard:blank, Wildcard Sub: blank
  9. 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

  10. … and save.
    Almost there…
  11. 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!

  12. 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.
  13. Set all values for ‘adcolumn’ to Hidden and submit.
  14. 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

Comments on this entry are closed.

css.php