Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set JS files to be display either header or footer #2

Open
Hirlysm831 opened this issue Dec 28, 2017 · 6 comments
Open

Set JS files to be display either header or footer #2

Hirlysm831 opened this issue Dec 28, 2017 · 6 comments
Assignees

Comments

@Hirlysm831
Copy link

Hello, good day i'm not used on posting issues in GitHub, bare me with this one thanks

is there a way we could set the .js files to be included on header and footer or its just me who don't know how to use properly the code thanks a lot.

@bkader
Copy link
Owner

bkader commented Dec 28, 2017

Hi.
On the master view page echo js_files wherever you want.

@bkader bkader closed this as completed Dec 29, 2017
@Hirlysm831
Copy link
Author

OKay simple echo js_files in when ever views right? supposed i had a 2 js files being declared in controller, i want the first js file to be header.php while the other one is place in the footer, placing simple echo js_files in the controller will result to duplicate js files both header and footer, how do we supposed to achieve this thanks

@bkader bkader reopened this Jan 10, 2018
@bkader
Copy link
Owner

bkader commented Jan 10, 2018

Well what you can do is to echo $js_files on the header, and in your controller do something like this:

$this->theme->set('extra_js', $this->theme->js('file' ...)
$this->theme->set('extra_js', js('file' ...) 

Then, in your master view file, echo it or check if it exists before, like so:

echo (isset($extra_js)) ? $extra_js : '';

@bkader
Copy link
Owner

bkader commented Jan 11, 2018

@Hirlysm831 please tell me if it worked for you so I can close this issue.

@bkader bkader closed this as completed Jan 19, 2018
@Hirlysm831
Copy link
Author

Yes, it helps resolve the conflict somehow, thanks, by the way can you do something like this one? https://github.com/terrylinooo/Codeigniter-Simple-Template-Library setting the js/css to be on header and footer, check on the library it has switch case statement, if you dont mind doing it on your free time, im willing to wait XD
Appreciate much for prompt response sir :D

@bkader
Copy link
Owner

bkader commented Jan 24, 2018

I will see what I can do.

Meanwhile, you can simply set a global variable (name it anything you want. i.e: js_in_header) and set it to false. Then in the main view file check if it's set to true or false to display JS tags in header or footer.
This solution is for ALL tags, not individual tags. There are plenty of possible workarounds but I will do some changes on the library as soon as possible.

@bkader bkader reopened this Jan 24, 2018
@bkader bkader self-assigned this Jan 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants