PHPackages                             webstractions/sage-xpress - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. webstractions/sage-xpress

ActivePackage[Templating &amp; Views](/categories/templating)

webstractions/sage-xpress
=========================

Extends Sage ~9-beta with Blade directives, component providers, streamlined configurations, and more.

v0.2.1(8y ago)285812[2 issues](https://github.com/webstractions/sage-xpress/issues)MITPHPPHP &gt;=7

Since Oct 13Pushed 8y ago4 watchersCompare

[ Source](https://github.com/webstractions/sage-xpress)[ Packagist](https://packagist.org/packages/webstractions/sage-xpress)[ Docs](https://github.com/webstractions/sage-xpress)[ RSS](/packages/webstractions-sage-xpress/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

Sage Xpress
===========

[](#sage-xpress)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/8fe53eff474d1be6d7ee2e1bb5d33ce240fda09c4c39cbbba844a96655b8d01e/68747470733a2f2f7472617669732d63692e6f72672f776562737472616374696f6e732f736167652d7870726573732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/webstractions/sage-xpress)

A collection of extensions, providers, and Blade revisions for your Roots\\Sage 9.x beta themes.

- **Blade Directives:** @directives for loop, query, sidebar, FontAwesome, and more.
- **Menu Provider:** Register nav menu and markup via configuration file.
- **Sidebar Provider:** Register sidebar and widget markup via configuration file.
- **Comment Form Provider:** Register comment form markup via configuration file.
- **Schema Provider** Quickly add schema.org markup via @schema directive.
- **Facade/Alias Support** Provide a "static" interface to classes that are bound to the Sage container.
- **Blade Fixes** Fixes Blade `@inject` directive and 5.5's `Blade::if()` method.

Requirements
------------

[](#requirements)

This package is specifically built for `Roots\Sage 9.0.0-beta.4` and above. It goes without saying that your development server needs to have `Php 7.0` or greater as well.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require webstractions/sage-xpress
```

Sage Xpress Setup
-----------------

[](#sage-xpress-setup)

Add to your `after_theme_setup` action in `app/setup.php` file. It is important that you make this addition **after** Sage's singleton for the `BladeProvider`:

```
add_action('after_setup_theme', function (){

  ...

  /**
    * Add Blade to Sage container
    */
  sage()->singleton('sage.blade', function (Container $app) {
      $cachePath = config('view.compiled');
      if (!file_exists($cachePath)) {
          wp_mkdir_p($cachePath);
      }
      (new BladeProvider($app))->register();
      return new Blade($app['view']);
  });

  // Copy this part into app\setup.php after_theme_setup action.
  // Make sure it follows the Sage singleton for the Blade Provider.
  (new \SageXpress\SageXpress(sage()))->bootstrap();

});
```

**Important** Since this package is introducing new Blade directives, you should clear your cached/compiled Blade files. Those files are located in `wp-content\uploads\cache`.

Configuration Files
-------------------

[](#configuration-files)

Currently, you have to copy and paste the sample config files into your theme `config` directory. You can find them in the `vendor\webstractions\sage-xpress\config` directory.

The configuration files are a major component of SageXpress that drives the Providers (more below).

- `app.php` Registers theme environment, providers, composers, and aliases.
- `blade-directives.php` For your custom Blade directives.
- `comments.php` Comment form configuration. Other comments related tasks.
- `menu.php` Register nav menus and configurations.
- `sidebar.php` Register sidebars and configurations.

Overview
--------

[](#overview)

Outside of one line of code that you need to add to `setup.php` and the config files, there is nothing else you need to do. Config files are automatically registered with the Sage Container, no messing with `functions.php`.

Additionally, your `setup.php` file should actually be leaner. No need for `widgets_init`, `register_nav_menus`, and funky `wp_nav_menu` callouts in your controllers or blade files. The providers automatically do the registration for you based on your configurations and there are Blade Directives to spew them out.

Facades and Aliases
-------------------

[](#facades-and-aliases)

You can now register `aliases` via the `config\app.php` configuration file. Currently, there are standard Laravel Facades for Blade, Config, Event, File, and View. Facades for SageXpress providers are in a state of flux and currently supports Comments, Menu, and Sidebar.

With Facades, you can reference bound providers with unruly instantiation and method calls like the following.

Instead of

```
sage('blade')->compiler()->directive('name', function ($expression) {
        // Handle the directive.
    });
```

You can:

```
Blade::directive('name', function ($expression) {
        // Handle the directive.
    });
```

Facades have some advantages. Rather than list the pros and cons of Facades, and how they work, please reference the [Laravel Facade Documentation](https://laravel.com/docs/5.4/facades).

The SageXpress Provider
-----------------------

[](#the-sagexpress-provider)

SageXpress providers are similar to Laravel Service Providers, but they contain additional methods for `config()` and `render()`. You can think of them as configurable components that can be rendered in a Blade view.

Providers are autoloaded via the `config\app.php` congifuration file during the SageXpress boot process. The providers are then bound to the Sage Container where you can use or reference them from your theme classes and controllers.

Providers handle WordPress-centric methods for registration, filters, etc. The `render()` method can be used for the creation of custom Blade directives.

### Blade Directives Provider

[](#blade-directives-provider)

Provides some handy Blade directives targetted mostly for WordPress use, but other helpful functionality as well.

There are a whole slew of directives, and requires its own [Blade Directives Documentation](https://github.com/webstractions/sage-xpress/tree/master/docs/blade.md).

One example, the `@loop` directive does a nice job of cleaning up your templates.

```
@loop

   {{-- Code inside of the loop --}}

@endloop
```

The directive will output this php.

```
if (have_posts()) :
  while(have_posts()) :
    the_post();

    // Code inside of the loop

  endwhile;
endif;
```

### Menu Provider

[](#menu-provider)

Configure your menus in `config\menu.php`. The `MenuProvider` will handle the registration with WordPress.

```
