Hi guys, I am trying to insert the value of a field (which is an image URL) in a CSS property. I am doing it through JS. This whole code will go in a theme file.
I am wondering whether something like this is correct in Drupal:

        drupal_add_js('jQuery(document).ready(function () {
          $(".myDiv")
          .css({"background":"url("
            . render($content['myField']) .
          ")"})
        });', 'inline');

Comments

VM’s picture

shouldn't add directoly to tpl.php files see: https://www.drupal.org/node/756722 for how to manage js in Drupal.