Billy ONeal Billy ONeal - 7 months ago 22
Javascript Question

How do I tell Netbeans that a section of code is Javascript?

I'm using the Zend Framework's javascript helpers of the form:

<?php $this->headScript()->captureStart(); ?>
//Javascript here
<?php $this->headScript()->captureEnd(); ?>

//Rest of view here


The problem is that Netbeans keeps complaining about code problems in the block, because it thinks it's an HTML, rather than a Javascript, block. Plus syntax coloring is broken.

Netbeans already has special comment hinting which you can use to apply a type to a variable when it can't be resolved by Netbeans automatically to tell it that we're writing Javascript in that range, rather than HTML?

Answer

Something like this:

<?php  $this->headScript()->captureStart(); ?>
//<script type="text/javascript">
var validJSsyntax = true,
    netbeansJShighlighting = true,
    problem = 'solved';
//</script>
<?php $this->headScript()->captureEnd(); ?>

Of course it will produce two useless lines in your JS output, but you can modify captureEnd() method to strip those for you.