In Laravel 4:
If you wanted the variable accessible in all your views, not just your template, View::share
is a great method (more info on this blog).
Just add the following in app/controllers/BaseController.php
class BaseController extends Controller
{
public function __construct()
{
// Share a var with all views
View::share('myvar', 'some value');
}
}
and now $myvar
will be available to all your views -- including your template.
I used this to set environment specific asset URLs for my images.