Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

In my template.php i am executing some inline javascript code. When executing, the result is a white screen of death (WSOD). The web servers error log says:

PHP Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in /template.php on line 89.

Line 89 is this one:

drupal_add_js("(function ($) {$('.altona_1').hover(function() {

And here comes my whole template.php:

<?php
function skh_omega_preprocess_page(&$vars, $hook) {
  drupal_add_library('system', 'ui.accordion');
  drupal_add_js("(function ($) {$('.altona_1').hover(function() {
    $( '.field-collection-container' ).accordion( {
      header: 'h4',
      active: 2,
      collapsible: true
      } );
    },
    function() {
    $( '.field-collection-container' ).accordion( {
      active: false,
      collapsible: true
    } );
  });
 })(jQuery);", array('type' => 'inline', 'scope' => 'footer'));
}

Do i have a wrong markup or what's the matter?

share|improve this question
    
So what about webserver's error log? JavaScript console log? And what do you need $vars['scripts'] = drupal_get_js(); for? Twice?.. –  Mołot Sep 1 '14 at 10:40
1  
WSOD's always have an underlying error message in the logs. You'll need to show us that. Also those are not functions, they're just lines of PHP code. Would be useful if you could show us what function/hook those lines of code are part of. –  Beebee Sep 1 '14 at 11:00
1  
So easy with the error log. Basically because you're wrapping your JS string in double quotes, PHP is trying to convert jQuery's $() into a PHP variable. You should wrap your JS string in single quotes, but use double quotes inside. So change the double quotes to single, and change the singles into doubles basically. –  Beebee Sep 1 '14 at 13:08
    
I edited my original question above and added server log and hook. –  Madam Adam Sep 1 '14 at 13:11
2  
Since you're using double quotes interpolation will kick in - you need to escape your $ characters with a backslash, or use single quotes (or a nowdoc) to wrap the string. Nothing Drupal-related as such, just PHP –  Clive Sep 1 '14 at 13:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.