Usage In Views

How to render your classes in layouts.

The package implements both a facade and Blade directive for usage in views.

Blade Directive Usage

The Blade directive is helpful for when you need to make use of Blade caching.

Simply use the @route2class_generate_classes directive in your layout file:

<body class="@route2class_generate_classes">

Note that this directive will run before all other Blade template code. As a result, any calls to the Route2Class provider in a view template will not take effect. Use a facade accessor instead if you must (see below).

📘

Blade Caching

If you're working locally, keep in mind your templates will be cached if enabled.

Clearing cache is easy:
php artisan view:clear

Facade Usage

The facade has two main differences from the Blade directive. The facade will not be cached by default, and since the code runs sequentially (not as a Blade directive), you can also modify classes with templates.

<?php
// This is possible, now:
Route2Class::addClass('test');
?>

<body class="{{ Route2Class::generateClassString() }}">

What’s Next