Templating and Scripts

Hello
Need some help with this situation:

  • I have a Layout.php page, that contains the page structure, and several variables, one of them it’s the $content.
    The $content var it’s “filled” in the requested pages, the normal behavior of a template…

So my problem is for example in one of the pages i have to use jQUery (validation/ui/whatever), so if i use the script tags only in the layout, the page will generate errors. If i add in the page the scripts tags, it will duplicate the js files (current file and layout) in some cases wired behavior because of the load order and it’s a bad practice. If i try to load them on the fly, while checking if it’s required or not in some pages i have errors, because the scripts are loaded asynchronous and aren’t ready when i need them…

So what’s the best way to solve this?
Sync script load on-the-fly (possible?)?

After writing this, i remember a possible solution.

In each page that i need scripts I’ll have an array var that contain the scripts names.
In the layout, another array variable with all the scripts needed for the all site.
Then when requesting the layout just, check the difference between the arrays and add the scripts that are missing.

Sponsor our Newsletter | Privacy Policy | Terms of Service