0

I have installed CodeSleeve asset-pipeline to manage and minify assets for my project. As I understood, all the scripts and stylesheets are controlled from manifest files located at: app/assets/stylesheets/application.css and app/assets/javascripts/application.js
That is all great, but what if I want to load different assets for different page? For example admin side of the application.
This situation is also mentioned in asset-pipeline documentation and recommended to use separate manifest files.

For example, if your application is silo'ed into admin section and user section then it probably makes sense to have a separate manifest file for each section.

Sounds great, but question remains. How?
Here is a similar question about asset-pipeline on Rails 3.1 and a somewhat complicated solution for such a obvious need, as is the need to include different assets in different sections of the application.
I still tried to make sense of that solution, but this is about Rails, so I still have no idea where are the manfiest files added in Laravel version?

Community
  • 1
  • 1
ruuter
  • 2,453
  • 2
  • 30
  • 44

1 Answers1

1

I must admit I first went much longer and complex path, hacking the config array with Laravel Event listener. Got it working though until I turned on production environment, which broke my admin section styles. Now after all the hair-pulling came back to asset-pipeline documentation and found the very simple solution which had been right in front of my eyes the whole time: All you have to do is add parameter to include tag, like this:

<?= javascript_include_tag('admin/application') ?>

This will point to folder assets/admin and look for application.js from that folder. Resulting html markup will be:

<script src="assets/admin/application.js" data-foo="bar"></script>

Same thing with stylesheets.

ruuter
  • 2,453
  • 2
  • 30
  • 44
  • I have tried this approach and it is breaking my site. I had two folders under /app/assets called 'desktop' and 'mobile'. When I added a link to the manifests = javascript_include_tag('desktop/javascript/application') ?> everything just blew up. – Bernard Nandwa Feb 28 '15 at 20:22
  • Sorry, I'm not sure what do you mean by "blew up". Please be more specific about what happens. Your description about what you did, seems to be correct. – ruuter Apr 03 '15 at 15:17
  • It can no longer load assets. – Bernard Nandwa Apr 06 '15 at 15:57
  • @BernardNandwa Sorry but it's impossible to figure out your error without any information. Please provide error message or something. Check what your debug console says? Does html mark-up generate? Does JS files actually exist where they should? – ruuter Apr 07 '15 at 22:02
  • When I made the changes to use separate manifests the css and js on the website broke and actually there were no errors logged. What I was attempting was exactly what your answer documented. I configured the application.js file and also for the application.css file just as the main application.js file to get everything in the tree. Cache cleared. Assets Cleaned. Nothing working. I am using the latest version of the asset manager for the 4.2 branch. Hope this helps. – Bernard Nandwa Apr 08 '15 at 08:42
  • What is the resulting HTML? src="assets/desktop/javascript/application.js" ? If so, does http://yourdomain.tld/assets/desktop/javascript/application.js exist? Do you have application.js file in desktop/javascript directory and it is a manifest file? – ruuter Apr 13 '15 at 16:01