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

Load different JS files for each template #30

Closed
nunodotferreira opened this issue Aug 8, 2014 · 9 comments
Closed

Load different JS files for each template #30

nunodotferreira opened this issue Aug 8, 2014 · 9 comments
Milestone

Comments

@nunodotferreira
Copy link

Hi Flovan

i'm wondering if it's possible to load a js file in one html file and not to load to a different html file!?

like this

index.html -> load main.js --- with all the files in the libs folder
company.html -> load main.js and otherfile.js just for this html template!

@flovan
Copy link
Owner

flovan commented Aug 8, 2014

Of course it is ;) Although it's only barely touched in the View specific files chapter, which is probably why you missed it.

You can have both page-specific CSS and JS files, by using the following name structure:

view-the-name-of-your-html-file.{js|css}
^^^^^

When initialising a new project, you will find dummy files for index.html in assets/sass (_view-index.sass) and assets/js (_view-index.js). To use these, just remove the underscore from the name and optionally rename them to the page you want them in. Of course you can also just add a new file without any of the default code—just do whatever you like most.

@flovan flovan added feature and removed feature labels Aug 8, 2014
@flovan
Copy link
Owner

flovan commented Aug 10, 2014

@nunodotferreira did you figure out how to make the page-specific assets work?

@nunodotferreira
Copy link
Author

Hi,

the feature that you describe i'm already using it! That's not it.

What i need is a solution to inject a specific js file in one specific html file. Not the main.js and not the page.js!?

@flovan
Copy link
Owner

flovan commented Aug 11, 2014

I don't think that's possible at the moment 😢

You could figure out a way around it such as placing your file in a new folder (eg. assets/js_manual) and including the script tag yourself, above where the other scripts get injected. If it needs jQuery to work, you'll have to move jQuery to the new folder and include it manually as well. Everything inside of assets/js is included automatically on every page (except for view-* files), so this is the only way to get some more control over this.

At some point it becomes too hard for me to provide a solution that takes into account every single use case. This (as was #15) is one of those cases. I'll tag it for the next release and see what I can do, but for now you'll have try using a non-intuitive way to get it done..

@flovan flovan added this to the v1.3 milestone Aug 11, 2014
@flovan
Copy link
Owner

flovan commented Aug 17, 2014

Good news @nunodotferreira, I have just found out that you can have page-specific lib files as well. I had never tried it before, but if you have for example view-index-jquery-1.11.1.js, it will only be included on the index page.

Can you try this out and see if it resolves this issue?

@nunodotferreira
Copy link
Author

I'll try it in my new project to see if this works!

@flovan
Copy link
Owner

flovan commented Sep 24, 2014

@nunodotferreira Any news on this? I am wrapping up on v1.3, but I would like to have all the issues assigned to this milestone fixed first. I you haven't yet been able to check up on this, I will push this forwards to a next release so I can move on.

@nunodotferreira
Copy link
Author

apparently this works fine!
i'm using this on my new work, and it's working.
if some issue appears, i'll post it here.

@flovan
Copy link
Owner

flovan commented Sep 24, 2014

Nice! Thanks for responding so fast :)

@flovan flovan closed this as completed Sep 24, 2014
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