Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Multiple Assets Named

Started by Muut Archive 11 years ago · 3 replies · 262 views
11 years ago

I see that to implement named assets one must first declare it here. Is there a way to have multiple js files loaded with one name?

11 years ago

Thank you for your quick response!

How can I declare my css and js in the system.yaml file? I don't want to have a plugin as some of the css files wouldn't be called on every page. I'd rather it be included in the core and have the option to turn certain css files off/on with twig, or page headers.

Currently we call named assets like so:

TXT

Would that be the same with CSS included? Or is this a good time to use something like

TXT

How would this look with css files included?

YAML
assets:
  css_pipeline: false
  css_minify: true
  css_minify_windows: false
  css_rewrite: true
  js_pipeline: false
  js_minify: true 
  collections:
    jquery: system://assets/jquery/jquery-2.1.3.min.js
11 years ago

The addJs() and addCss() methods actually call the add() method for named collections because you can have a mix of CSS and JS files in the collection. If you wanted to define a collection via the system.yaml file you could have something like:

YAML
assets:
  collections:
    jquery: system://assets/jquery/jquery-2.1.3.min.js
    mycol:
      - theme://css/mycol.css
      - theme://js/mycol.js
      - http://something/else.css
      - http://another/url.css

Then simple add the collection via:

TWIG

{{ do assets.add('mycol') }}
---

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1322 9 years ago
Archive · by Muut Archive, 9 years ago
2 918 9 years ago
Archive · by Muut Archive, 9 years ago
2 4048 9 years ago
Archive · by Muut Archive, 9 years ago
1 2922 9 years ago
Archive · by Muut Archive, 9 years ago
3 1106 9 years ago