Zend framework and code formating in view files

If i use HeadScript Helper ( http://framework.zend.com/manual/1.12/en/zend.view.helpers.html#zend.view.helpers.initial.headscript ) i can't use code formating.

For example view file with using HeadScript Helper:

<?php $this->headScript()->captureStart(); ?>
function foo() {
alert('foo');
}

<?php $this->headScript()->captureEnd(); ?>
<span>some html code</span>
<?php
$somePhpCode = "";
?>

If i try to format this code then javascript between  <?php $this->headScript()->captureStart(); ?> and <?php $this->headScript()->captureEnd(); ?> will be not formated.

Can i assign alternative tags for start and end javascript code?
I will be happy for any ideas how to solve this problem.

1 comment

Hi there,

Can i assign alternative tags for start and end javascript code?

I believe currently it is not really possible (but I do not work with ZF, so cannot be 100% sure on this; maybe there is some plugin for ZF that can do this). Similar old thread: http://devnet.jetbrains.com/message/5451433

I can offer you some "workarounds" but they are not elegant at all and require some code modification. Plus, code reformat does not seem to work properly there as well (when invoked directly, at very least on your example code).


You can write your code this way, which will automatically inject JavaScript language into HEREDOC:

<?php $this->headScript()->captureStart(); ?>
<?= <<<JS
function foo() {
alert('foo');
}
JS;
?>
<?php $this->headScript()->captureEnd(); ?>

Selecting JS code and calling Reformat on it does not seem to work (does nothing here). But, if you Alt+Enter (or click on light bulb) while standing inside such language injection region and choose "Edit JavaScript Fragment", you will be able to reformat JS code in that special edit window.

0

Please sign in to leave a comment.