0

I want to use $node->title in the script tag so that I can get data dynamically for particular titles. So I am not getting how can I achieve this. I tried like below, but not worked.

 <script type="text/javascript">
     var job_title = $node->title;
     var container_id = "#footer";
     Springest.getTrainings(job_title, container_id);
  </script>

Thanks for any suggestions.

1
  • Please mention which file you're trying to use this code, i.e. page.tpl.php, node.tpl.php. This will help provide better solution to your problem
    – Yogesh
    Commented Nov 17, 2016 at 6:34

1 Answer 1

0

You can simply embed php in javascript, however the way you are adding your js is not recommended, please look around drupal way of adding js and sending values from php to javascript.

Having said that, the following code might help you-

<script type="text/javascript">
     var job_title = <?php echo $node->title; ?>;
     var container_id = "#footer";
     Springest.getTrainings(job_title, container_id);
  </script>

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.