开发者

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 开发者_StackOverflow中文版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?


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.


From my knowledge this functionality is not yet implemented in the current version of NetBeans IDE that is 6.9.1. I can show you a workaround through which you can fool the NetBeans IDE to highlight the Javascript as a script section, and also keeps the PHP processor happy. It will look like following code snippet:

    <?php $this->headScript()->captureStart(); ?>
    <?php if( false ) {?><script><?php } ?>
        // keep Javascript here
    <?php if( false ) { ?></script><?php } ?>
    <?php $this->headScript()->captureEnd(); ?>

I have tested this in NetBeans IDE 6.9.1


I was actually just reading about this yesterday in their blog:

Their HTML in PHP parsing has been flaky, especially with indenting incorrectly short/alternate form code, but the latest nightly builds (I presume those after 201010060000) have improvements in that area. I haven't tried it yet but give it a shot.


print problematic code with PHP

<script <?PHP echo 'type="text/template"?> id="Template-1">
    //your code here
</script>

If you print all script tag with PHP, NetBeans perfectlly format HTML tags

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜