2

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?

4 Answers 4

7
+100

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.

Sign up to request clarification or add additional context in comments.

4 Comments

// is used for comments and which is incorrect syntax for HTML
It is used in comment in case it would appear in <script> block (to be valid js syntax and do not throw any errors), in HTML it is just a textNode and NetBeans does not alert about using textNode inside <head> block, so it works just as OP wanted.
+1 for good answer, wish I could +1 again for hilarious code snippet.
Checkmarked + bountied because this is more readable than Tushar's answer. Both are good answers though.
4

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

Comments

0

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.

1 Comment

This is about how PHP tags are handled in general -- it doesn't tell Netbeans anything about Javascript.
-1

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

1 Comment

If NetBeans thinks that's an appropriate solution, I'd scrap it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.