Question

I've a problem with drupal paths in one view that I building. Right now my view has this form: contents/2/6.

Where 2 and 6 are the Ids of two nodes, I'd like to manipulate these ids to translate them let's say the title of those nodes.

I can not do this from the view because I'm sending these values to a panel, and the panel MUST received the ids of the nodes.

So to sum up, I just want to rewrite (like pathauto does) these ids to title, can I do that? Is there an specific module for this?

Thanks!

Was it helpful?

Solution

If I understand you correctly, you want to keep the original paths 'content/[nid_x]/[nid_y]', but add additional URL aliases for those with more 'speaking' path elements from the nodes (e.g. titles). If that is correct, you have two options:

First, you can do it manually by defining URL aliases for 'content/[nid_x]/[nid_y]' under 'admin/build/path/add'. This is easy to do, but probably not what you are looking for, if you need many of those aliases.

Second, you can do it programmatically by means of the path_set_alias() function. Using the function is pretty straight forward - the only problem might be where to trigger it. From your description it is not clear to me where/when those views get created, so it's hard to come up with a suggestion - maybe you can edit your question to be a bit more specific on that.

If you want to create that view URL aliases for specific node combinations, you could try to use the 'insert', 'update' and 'delete' operations of hook_nodeapi() to trigger the alias creation. Obviously, this would only work if there is a coherent rule that would allow you to decide from code for which nodes to create an alias or not.

Once you have an URL alias in place for a certain path, it will be used instead of the original one whenever a link to that path gets created via the l() function. So e.g. if you create a menu entry pointing to 'content/2/6', the used URL would automatically be the alias you created for that path.


Edit: Just in case you end up creating aliases programmatically - If you use pathauto anyways, you could/should use its pathauto_cleanstring()function (from 'pathauto.inc') to ensure that your generated URLs are properly escaped/rewritten to allowed characters.

OTHER TIPS

There's a way to use the custom url function to create dedicated custom URLs. If you're using panels though I'm not sure if you'll want to do it this way because it's very static.

function custom_url_rewrite($op, $result, $path) {

  if ($op == 'alias') {
    if (preg_match('|^[node_id#_here](/{0,1}.*)|', $path, $matches)) {
      return '[desired_alias]'. $matches[1];
    }
  }

  if ($op == 'source') {
    if (preg_match('|^[node_id#](/{0,1}.*)|', $path, $matches)) {
      return '[desired_source]'. $matches[1];
    }
  }

  return $result;

}

You'll want to substitute the node id#s with your own as well as your own desired aliases and sources. Hope this helps.

Perhaps usefull aswell:

change the initiating links by using a view to build the link using token replacement like <a href="nodeview/[title]/nid" title="[title]">link tekst</a> and handle the node in a view with path exa nodeview and arguments null, null, nid f.i.

for more convoluted links us a view php field to build the string..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top