View Helpers

Session The Session class helps you handle session items and flash messages. Interacting with session You can use the set(), get() and has() methods to interact with session items. Session::set(‘hello’, ‘world’); if(Session::has(‘hello’)) echo Session::get(‘hello’); The above script will output this: world Flash messages You can use the flash() method to deal with flash messages. Flash messages will be available via the get() method only

WordPress Templates

If you need to use some WordPress standard templates in you theme, you can do it with Alter. Just use the template() method from the Response object. Route::get(‘/search’, function(){ $this->template(‘search’); // Will require (not render) your_theme/search.php });

Views and Layouts

Alter uses all the power of Twig to render templates. You can render a view using the render() method of Callback object. Route::get(‘/’, function(){ $this->render(‘index’); // Will render views/index.html }); You can also organize your views into folders: $this->render(‘cars.index’); // Will render views/cars/index.html And pass data to the views: $this->render(‘cars.index’, [‘car’ => $car]); // Will render views/cars/index.html passing $car Using Twig


Alter’s Route component is built using the WordPress Rewrite API and FastRoute. Creating routes You can create routes simply calling the static methods of the Route class: Route::get(‘/hello’, function(){ // Here you are! }); You can also specify HTTP methods to routes like GET, POST, PUT, DELETE, PATCH and OPTIONS. Route::post(‘/hello’, function(){ // A POST request to /hello }); Passing


Alter’s defaults configuration is located under vendor/alterfw/ampersand/config.php. To override the default configuration just copy the config.php file to your theme’s root directory and made the changes you need.