I have 2 views setup - one is for a directory listing of nodes and the other displays an individual node from that directory.

The directory view is visible at /directory and can be filtered by letter (e.g. /directory/b will show all nodes whose title starts with b)

Currently, the directory listings link to /directory/show/[nid] but I would like them to be friendlier. For example /directory/show/example-title.

I can get close to this if I check 'Output this field as a link' on the Title field and set the 'Link path' to directory/show/[title]. However, that displays the link as /directory/show/Example Title.

Is it possible for this link to be displayed as /directory/show/example-title somehow?

2 Answers 2


First way: For second Views I assume argument handling is used (NID send as argument).

  1. So you should modify this argument,
  2. Add/change this argument validation - select PHP code
  3. There you should check if this $handler->argument is numeric
  4. if not, try find node by title ($handler->argument will title),
  5. if found, assign to $handler->argument found NID.
  6. Return in code TRUE if argument is numeric or node found by title.

Minus of this for nodes with the same titles, so you can use next way.

Another way is using Rules for that:

  1. Add rule for node creation/editing
  2. Add action and use next PHP code for inserting new alias:

         global $language;
         $path = 'node/' . $node->nid;
         $alias = 'directory/show/' . $node->title;
         path_set_alias($path, $alias, NULL, $language->language);

Be sure that $node accessible in your Rules PHP code action, if not, seek patterns like [nid], etc.
Also you should resave all your required nodes for creating new aliases for these nodes, recommend to use for it VBO module.

  • The individual node is also being displayed with a view, I thought about linking straight to the node by it's URL/path alias but the view has a different interface that allows for some filtering/unique navigation to happen. (unfortunately I inherited this project so can't easily make major changes)
    – James
    May 24, 2012 at 2:32
  • Answer changed due to single node displaying in Views.
    – Nikit
    May 24, 2012 at 3:32
  • Argument handling now added...
    – Nikit
    May 24, 2012 at 3:50

I solved this in the end by overriding the title field template for my directory view and generating the links in there.

So I had started with output like this:

<a href="/directory/show/Example Page">Example Page</a>

and my overriding title field template contained:

<a href="/directory/show/<?php echo str_replace(' ', '-', strtolower($variable['row']->node_title)); ?>">
    <?php echo $variables['row']->node_title; ?>

Which gave me the desired output:

<a href="/directory/show/example-page">Example Page</a>

If there's a better solution please let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.