2

I am trying to create an alternative view and found this answer:

How to load view from alternative directory in Laravel 4

which suggested using this code

View::addLocation(app('path').'/themes/default');
View::addNamespace('theme', app('path').'/themes/default');

But cannot decide where to declare these statements . In which file can I use this code?

start.php,path.php,app.php,global.php or in another file .

Community
  • 1
  • 1
JohnTaa
  • 2,722
  • 2
  • 15
  • 15

2 Answers2

2

If using the app/config/view.php configuration file to add view loading locations (via the paths array) is not enough for your needs, you can probably fit that into a service provider.

Laravel actually uses the View Library's Service Provider to register the view paths locations (based on the app/config/view.php config file as mentioned).

One thing you can do is add your own service provider class and add in your view logic there, in order to add a location / namespaces as you need. (You can even have your service provider read your own configuration files in order to determine locations/namespaces).

If you need help creating a service provider/don't know where to put one, read this on creating a Laravel application library.

fideloper
  • 12,213
  • 1
  • 41
  • 38
  • could it be more simple than this ? when the View class is ready 'Loaded' ? – JohnTaa Oct 01 '13 at 23:44
  • It can be more simpler than that! Pop it in one of the `start.php`/`global.php` files you listed - the code can go there just as easily! For "best practices", I think you'll find a general preference around creating an application library - it's more maintainable in the long run. However, to each their own - you may not need it for any "long term" project. I certainly write plenty of "short-term" apps which don't use a more complicated code structure. – fideloper Oct 02 '13 at 13:03
1

If that's all you'll be doing, putting it inside app/start/global.php works just fine. There's really no need for a new service provider for such a simple task.

However, if after some time you realize your global.php file is starting to get too heavy and messy, then you should go for a service provider, as @fideloper mentioned.

rmobis
  • 26,129
  • 8
  • 64
  • 65