Declared a variable in settings.php

$conf['my-variable'] ="my-variable-value";

Added inline javascript


Need to print variable values from Drupal.setttings in inline js

  window.my-val = Drupal.settings.my-variable;


So the output on page is comming up like

<script type="text/javascript">
window.my-val =Drupal.settings.my-variable; 

But I need it should be like below for seo requirement

<script type="text/javascript">
window.my-val = "my-variable-value";

I think you're over-estimating the potential SEO value of making such a change, but if you don't want to use Drupal settings you can just interpolate the value into a static string and use that:

$var = variable_get('my-variable');
$js = <<<EOF
function() { 
  window['my-val'] = '{$var}';
drupal_add_js($js, 'inline');

I'll leave data-sanitising up to you, how far you need to go will depend on the source of the variable.

  • Thanks, a lot for reply , let me check if it would work. – Rohit Tiwari Jan 22 '15 at 16:19

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.