Welcome Guest, Not a member yet? Register   Sign In
Parsing php in javascript
#1

[eluser]Maglok[/eluser]
Alright this is going to get a little complicated so bear with me.

I have several subdomains each with their own index.php in those index.php's I define what skin the site uses. So skin1.domain.com and skin2.domain.com have the proper colors.

Each template has a different css. Easy enough. I use carabiner to combine css and javascript (css and js thus each being their own file) to reduce the amount of http requests.

I am now in the process of streamlining the coding. At the moment I have snippets of JS code for each script I need initiated. Since not every page needs every snippet I am moving each snippet to a javascript file of it's own which I include on a page by page basis with carabiner.

For example this is how the tinyMCE init looks like:

Code:
[removed]
        tinyMCE.init({
            mode : "specific_textareas",
            editor_selector : "editor",
            plugins : "spellchecker",
            theme : "advanced",
            theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,|,cut,copy,paste,|,link,unlink,anchor,|,bullist,numlist,blockquote,|,outdent,indent,|,hr,image,spellchecker",
            theme_advanced_buttons2: "",
            theme_advanced_buttons3: "",
            theme_advanced_default_background_color : "#FFFFFF",
            spellchecker_languages : "+Dutch=nl,English=en",
            content_css : "<?php echo APP_MAIN; ?>css/<?php echo APP_SITE; ?>.css",
            remove_script_host : false,
            relative_urls : false,
            save_enablewhendirty : true
        });
    [removed]

You will notice I echo APP_MAIN and APP_SITE. Those are globals that don't get parsed in the javascript file if it is not inline.

I googled around some and people seem to suggest to tell apache to parse javascript by php like so:

Code:
AddHandler application/x-httpd-php .js

This doesn't work. I am even bypassing carabiner for it at the moment. TinyMCE does initialize, but it isn't taking the php echo-ing.

I could of course create a library or controller or so that outputs the correct code snippets, but I really rather keep all of that out of CI and just in a javascript scripts dir.

Anyone follow what I am trying to achieve?


Messages In This Thread
Parsing php in javascript - by El Forum - 12-24-2010, 05:10 AM
Parsing php in javascript - by El Forum - 12-24-2010, 05:25 AM
Parsing php in javascript - by El Forum - 12-24-2010, 06:10 AM
Parsing php in javascript - by El Forum - 12-28-2010, 09:02 AM
Parsing php in javascript - by El Forum - 12-29-2010, 05:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB