0

Declared a variable in settings.php

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

Added inline javascript

drupal_add_js("array('my-variable'=>variable_get('my-variable'))");

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

drupal_add_js("jQuery(document).ready(function(){
  window.my-val = Drupal.settings.my-variable;

})",'inline');

So the output on page is comming up like

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

But I need it should be like below for seo requirement

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

1 Answer 1

1

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}';
}
EOF;
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.

1
  • Thanks, a lot for reply , let me check if it would work. Jan 22, 2015 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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