Reply to comment

hi dominique (suggestion: add

hi dominique

(suggestion: add the datetime to your article posts)

great article. was exactly what i was looking for. my issue was around being able to create drupal links on the server side, and pass them to my javascript. needed to be able to have ajax working, whether the webserver was rewriting urls or not.

so, you gave me the technique i needed. one small adjustment i would add, is to do a path check with a static var, to keep from inserting this javascript where you don't need it, or inserting it multiple times on a page.

<?php
function module_name_init() {
  
// Only add on specific pages
  
if (arg(1) === 'module_name' && arg(2) === 'mypath' ) {
    static 
$complete FALSE;
    
// Only need to do once per page.
    
if (!$complete) {  
      
drupal_add_js(array(
        array(
        
'module_name' => array(
          
'apikey' => variable_get('module_name_apikey'''),
        )
      ),
      
'setting'
      
);
      
$complete TRUE;
    }
  }
?>

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><img><p><b><i><table><th><tr><td><blockquote><br /><img /><tbody><span><strike>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <codes>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.