1

How do I grab the Node ID in the URL of the current page and pass it through a link?

1) The URL on the current page is in the format: website.com/parameter/parameter/parameter and the third parameter is the Node ID. 2) I want to grab that Node ID and put it into a link on that page like Link

The screen capture illustrates this.

enter image description here

screen capture

2
  • Using URL arguments in a View is evil. Don't do it. Views can be rendered in different paths. The Ajax previews for example. The best way would be to write a Views header or footer plugin, that will use the $view->args to get the node ID which is already available in the View. However, for those who want it dirty, Views PHP module can help.
    – AKS
    Jun 1 '15 at 6:00
  • So be more specific about where I'm putting the link: In a View, under Header, I have added a Global: Text area, changed the format to Full HTML. And in the text area, I've put the link. Jun 1 '15 at 12:24
0

enter image description here

enter image description here

1) You just need to add a contextual filter of "Content: Nid".

2) Then select Provide Default Value, type: Content ID from URL.

3) Add a field of Nid and check mark the box that says "exclude it from display".

4) Add a custom field, <a href="blahblahblah[nid]">Deliberables</a>

PS: Make sure the nid field is above the custom field so the custom filed can use the nid token.

5
  • I think he has already done this. But there is no way in Views to use the argument input in views at the moment.
    – AKS
    Jun 1 '15 at 6:02
  • So be more specific about where I'm putting the link: In a View, under Header, I have added a Global: Text area, changed the format to Full HTML. And in the text area, I've put the link. Jun 1 '15 at 12:25
  • yes it goes in the Global: Custom text, Text box.
    – No Sssweat
    Jun 1 '15 at 12:42
  • AyeshK is right, I did that on the View page before this one. Now that the Node ID has landed on this View page, how to grab it and pass it along to the next page? Jun 1 '15 at 13:34
  • You want to pass NID 117 to page 118?
    – No Sssweat
    Jun 1 '15 at 20:17
0

Build your own token!

Your token then could analyse the current URL - double and triple validate it (don't let your page be hijacked!!!) - and return the discovered node-id.

Views allow usage of tokens everywhere they make sense - guess you'll have no problem to use it in a link of a views-footer/header area.

https://api.drupal.org/api/drupal/includes!token.inc/7

3
  • I don't have a programming background. Is there some approach to building tokens visually? Jun 1 '15 at 12:26
  • since I am programming a lot with Drupal I never looked for a visual way to create tokens. sorry.
    – gue
    Jun 1 '15 at 21:50
  • Just googled a bit: Maybe you have luck with a Drupal built in token: "Page argument" see drupal.org/node/390482#token-current-page
    – gue
    Jun 1 '15 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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