tattersoftware / codeigniter4-assets

Asset handling for CodeIgniter 4
MIT License
50 stars 12 forks source link

Configure routes dynamically #7

Closed barkdoll closed 4 years ago

barkdoll commented 4 years ago

Awesome work on this project!

So forgive my lack of understanding on this service library, but I was just wondering if it is possible to configure this dynamically.

The reason I ask is that I would like to use some logic to build the $routes property.

MGatner commented 4 years ago

Thanks for the interest! I’m open to suggestions and edits, but I don’t think I understand your question. It sounds like you are using the Assets library to load JS/CSS automatically based on the route. You want to build routes different than the default? You can always specify a route with setRoute() - does that help?

MGatner commented 4 years ago

service('assets')->setRoute(‘my/custom/route’)->css();

barkdoll commented 4 years ago

Thanks for the interest! I’m open to suggestions and edits, but I don’t think I understand your question. It sounds like you are using the Assets library to load JS/CSS automatically based on the route. You want to build routes different than the default? You can always specify a route with setRoute() - does that help?

Thanks for pointing me to setRoute(). I think it's what I am looking for. I will test drive it a bit. I just have one question left. Is it possible for me to set multiple routes and combine asset route collections or would the last setRoute() call override any previous calls?

Example:

service('assets')
  ->setRoute('custom/route')
  ->setRoute('extra/library/route')
  ->js();
MGatner commented 4 years ago

Currently the route is a single static entry, but there is nothing to prevent you from making separate calls for each route:


service('assets')->setRoute('custom/route')->js();
service(‘assets’)->setRoute('extra/library/route')->js();
MGatner commented 4 years ago

You might also want to leverage the config file, since it looks like you may be trying to replicate some of its function. There you can define as many explicit assets to load for whichever routes you want, regardless of the auto detection.

barkdoll commented 4 years ago

Currently the route is a single static entry, but there is nothing to prevent you from making separate calls for each route:

service('assets')->setRoute('custom/route')->js();
service(‘assets’)->setRoute('extra/library/route')->js();

You might also want to leverage the config file, since it looks like you may be trying to replicate some of its function. There you can define as many explicit assets to load for whichever routes you want, regardless of the auto detection.

Awesome. This all helps a lot. Thanks so much bro.