0

I am having PHP code inside my JavaScript file, which is processed by the server by setting the handler for the .js file extension to php5-script using a .htaccess. I tried opening the .js file in Aptana Studio using PHP Source Editor and JavaScript Source Editor, however, both editors highlight the php code as syntax error. I couldn't find an option in the settings where I can set the file type to a mix of PHP and JavaScript, or disable syntax error highlighting for PHP code in JavaScript, or anything else.

I have found a similar question but this is just related to the PHPStorm IDE which I do not want to use.

The content of my .js file currently looks like this:

<?php
header('Content-type: application/javascript');

$app_base_path = $_GET['_app-base-path'];
$app_route = $_GET['_app-route'];
?>

$(function() {

    var APP = {

        // syntax errors are thrown here
        // the single quotes could be escaped to reduce syntax errors
        // looking for a way to make a code like this possible without any syntax errors
        base_path: '<?= $_GET['_app-base-path'] ?>',
        route: '<?= $_GET['_app-route'] ?>'

    };

    $('body').append('APP.base_path: ' + APP.base_path + ' --- APP.route: ' + APP.route);

});
Community
  • 1
  • 1
sfandler
  • 610
  • 5
  • 23

1 Answers1

0

I previously read your question wrong. My bad. If php is NOT parsing the <?= ?> tags, make sure it's enabled in php.ini

Unless the string data in the $_GET parameters contain strings with single quotes in them, you shouldn't have an issue.

Paul Carlton
  • 2,785
  • 2
  • 24
  • 42
  • Thanks for your answer, sorry for my late reply. I think i formulated my question wrong: I want to stop my editor (Aptana Studio) marking these two PHP code parts as error or syntax error highlighting them. – sfandler Oct 19 '15 at 22:37
  • 1
    Ah! OK! That makes sense, was a little confused there. You know, you could have it as a .php extension rather than a .js extension and then in your htaccess just point the .js extension to the php extension and that would take care of your syntax error issue. – Paul Carlton Oct 20 '15 at 15:56
  • Well, then I could also just open the .js file with Aptana's PHP Source Editor.. However this doesn't solve my problem, because then the javascript code is not syntax highlighted. – sfandler Oct 20 '15 at 19:31
  • Have you tried this? http://stackoverflow.com/questions/811656/how-can-i-get-html-syntax-highlighting-in-my-editor-for-cakephp – Paul Carlton Oct 20 '15 at 20:16
  • Other than that unless there's a way to add syntax highlighting to a file extension, I think it's something someone with a lot more experience with Aptana should be helping you out with. I'm a PHPStorm, PyCharm, RubyMine guy. Personally, I'd go with my suggestion and just add something like .js.php to the extension so you know it's a .js file with php and edit it with your php editor instead. – Paul Carlton Oct 20 '15 at 20:25
  • Yes, I had a look at it. This doesn't help me since this would only let my apply a specific editor to a file type. What I would need is applying a mix of the PHP Source Editor and JavaScript Source Editor to my .js file. – sfandler Oct 20 '15 at 20:28
  • The problem when renaming the file to .php extension is that I get not syntax highlighting for JavaScript code in there. Well, I think I have to keep coding with either the black JavaScript code or the PHP syntax error highlightings. However, thanks for your help. – sfandler Oct 20 '15 at 20:31
  • 1
    Might I offer one more suggestion: Language Injections with PHPStorm would take care of this for you https://confluence.jetbrains.com/pages/viewpage.action?pageId=53315225 – Paul Carlton Oct 20 '15 at 20:34
  • I would like to stay in Aptana since I'm developing with it for years now, but I think I have to give PHPStorm a try. Thanks for your suggestion ;) – sfandler Oct 21 '15 at 08:09