Blade Templates

Sage uses Laravel's Blade templating engine.

Passing data to templates

Sage includes a sage/template/{$class}/data filter that can be used to pass data to templates. This is the most simple way to pass data.

add_filter('sage/template/page/data', function (array $data) {
    $data['header_image'] = get_field('header_image');
    $data['header_content'] = get_field('header_content');
    return $data;

Controller can also be used to pass data to templates.

WP-CLI utility

blade-generate is a WP-CLI package that can be used to compile, wipe, and clear Blade templates. Install blade-generate by running:

wp package install

After installing blade-generate you can run the following commands:

  • wp blade compile
  • wp blade clear
  • wp blade wipe

Join over 6,000 subscribers on our newsletter to get the latest Roots updates, along with occasional tips on building better WordPress sites.

Looking for WordPress plugin recommendations, the newest modern WordPress projects, and general web development tips and articles?

“Easily the best WordPress email I get.” Colin OBrien

Follow us on Twitter @rootswp

Ready to checkout?