English 中文(简体)
Drupal view and path urls
原标题:

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!

最佳回答

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.

问题回答

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..





相关问题
Drupal Multi-language: Simple strings not translated

I m adding additional languages to a Drupal site that I m building. Getting the translation of content working is fairly easy using the Internationalisation module. Yet, simple things such as date ...

Setting up a WYSIWYG editor for Drupal site users [closed]

Looking through the Drupal contrib modules, and after a few Google searches, it becomes evident that there are any number of choices and combos available to set up a WYSIWYG editor in Drupal. I m ...

Change size of user/password login box

I don t know how to change the size of the login username/password boxes on the drupal site that I m trying to build. I m stumbling through the theming, and don t know where to find the file that ...

How does Drupal provide an edit/review/publish model?

How does Drupal support a means to update and review a website before it is published? Does it only allow you to preview a page at a time before you publish it or is there a way to create a site ...

Term for rotating header

I m looking for terminology that describes this behavior: The header of a web-page contains a different image every time you visit it. Update: It is not an advertisement, but images related to the ...

Has anyone checked out Drupal 7? [closed]

Has anyone checked out a copy of Drupal 7 yet? What do people think? I m pretty excited about the PDO and all of the designers I work with a very excited about the new admin interface/structure. Do ...

热门标签