Getting the node ID of a page making a $.post request

  1. function mymodule_node_view($node, $view_mode, $langcode) {
  2. if ($view_mode == 'full') {
  3. $setting = array('mymodule' => array('currentNid' => $node->nid));
  4. drupal_add_js($setting, 'setting');
  5. }
  6. }


Then on the client side you'll have access to it through Drupal.settings:

var currentNid = Drupal.settings.MYMODULE.currentNid;

English
Категория: 
The code has been tested and works
Мультитег: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Target Image