PHPackages                             dawidurbanski/sage-directives - 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. dawidurbanski/sage-directives

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

dawidurbanski/sage-directives
=============================

A set of Blade directives for use with Roots Sage.

v1.0.6(7y ago)01.4kMITPHPPHP &gt;=7.0

Since Oct 18Pushed 7y ago1 watchersCompare

[ Source](https://github.com/dawidurbanski/sage-directives)[ Packagist](https://packagist.org/packages/dawidurbanski/sage-directives)[ Docs](https://github.com/dawidurbanski/sage-directives)[ RSS](/packages/dawidurbanski-sage-directives/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (10)Used By (0)

Sage Directives
===============

[](#sage-directives)

[![Latest Stable Version](https://camo.githubusercontent.com/27b376f3a75161c02ab8ee5ac102ba822e2cc1b4363a9e94a271d5e8ca61ede3/68747470733a2f2f706f7365722e707567782e6f72672f6c6f6731782f736167652d646972656374697665732f762f737461626c65)](https://packagist.org/packages/log1x/sage-directives) [![Total Downloads](https://camo.githubusercontent.com/ad4f00c34e5b6bab8dd567bd762c8cb3de5d53ef52984a0a16e4bac89bdef0ad/68747470733a2f2f706f7365722e707567782e6f72672f6c6f6731782f736167652d646972656374697665732f646f776e6c6f616473)](https://packagist.org/packages/log1x/sage-directives)

Sage Directives is a simple Composer package adding a variety of useful Blade directives for use with Sage 9.

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

[](#requirements)

- [Sage](https://github.com/roots/sage) &gt;= 9.0
- [PHP](https://secure.php.net/manual/en/install.php) &gt;= 7.0
- [Composer](https://getcomposer.org/download/)

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

[](#installation)

Install via Composer:

```
composer require log1x/sage-directives
```

Usage
-----

[](#usage)

Once Sage Directives is installed with Composer, it is automatically loaded and is ready for use. If a directive appears to not be rendering properly, please make sure you clear your Blade cache before further debugging or opening an issue.

[WordPress](#wordpress)[ACF](#acf)[Helpers](#helpers)[@query](#query)[@fields](#fields)[@layouts](#layouts)[@condition](#condition)[@posts](#posts)[@field](#field)[@layout](#layout)[@global](#global)[@title](#title)[@hasfield](#hasfield)[@group](#group)[@set](#set)[@content](#content)[@isfield](#isfield)[@option](#option)[@unset](#unset)[@excerpt](#excerpt)[@sub](#sub)[@hasoption](#hasoption)[@extract](#extract)[@shortcode](#shortcode)[@hassub](#hassub)[@isoption](#isoption)[@explode](#explode)[@user](#user)[@issub](#issub)[@options](#options)[@implode](#implode)[@guest](#guest)### WordPress

[](#wordpress)

The following directives are specific to WordPress core functionality.

#### @query

[](#query)

`@query` initializes a standard `WP_Query` as `$query` and accepts the usual `WP_Query` [parameters](https://codex.wordpress.org/Class_Reference/WP_Query#Parameters) as an array.

```
@query([
  'post_type' => 'post'
])
```

#### @posts

[](#posts)

`@posts` begins the post loop and by default, assumes that `WP_Query` is set to `$query` (which is the case when using `@query`). It is wrapped in a `have_posts()` conditional and thus will return `null` if no posts are found.

`@endposts` is available to end your loop and `have_posts()` conditional as well as resetting your loop with [`wp_reset_postdata()`](https://codex.wordpress.org/Function_Reference/wp_reset_postdata).

```
@query([
  'post_type' => 'post'
])

@posts
  @title

    @content

@endposts
```

If an instance of `WP_Query` is passed to `@posts` as a variable, it will use that instead.

```
@php
  $My_Query = new WP_Query([
    'post_type' => 'post'
  ]);
@endphp

@posts($My_Query)
  @title

    @content

@endposts
```

If `$query` is not defined and a variable is not passed to `@posts`, it will use the main loop from the `$wp_query` global.

#### @title

[](#title)

`@title` simply echo's the current posts title using [`get_the_title()`](https://developer.wordpress.org/reference/functions/get_the_title/). It can also accept a specific post as a parameter.

```
@title
@title(123)
```

#### @content

[](#content)

`@content` simply echo's the current posts content using [`the_content()`](https://developer.wordpress.org/reference/functions/the_content/).

```
@content
```

#### @excerpt

[](#excerpt)

`@excerpt` simply echo's the current posts excerpt using [`the_excerpt()`](https://developer.wordpress.org/reference/functions/the_excerpt/).

```
@excerpt
```

#### @shortcode

[](#shortcode)

`@shortcode` simply echo's the provided shortcode using [`do_shortcode()`](https://developer.wordpress.org/reference/functions/do_shortcode/).

```
@shortcode('[my-shortcode]')
```

#### @user

[](#user)

`@user` is a simple `is_user_logged_in()` conditional to display specific content only when a user is logged in. It can be closed using `@enduser`.

```
@user
  You are logged in!
@enduser
```

#### @guest

[](#guest)

`@guest` is a simple `!is_user_logged_in()` conditional to display specific content only when a user is not logged in. It can be closed using `@endguest`.

```
@guest
  You must be logged in to view this content.
@endguest
```

### ACF

[](#acf)

The following directives are for use with Advanced Custom Fields. If ACF is not installed and activated, they will not be initialized.

#### @field

[](#field)

`@field` does what you would expect it to do and echo's the specified field using `get_field()`. In an attempt to help keep things clean, it can also intelligently accept parameters to assist in pulling specific values if your field happens to be an array (e.g. an image field). This is done simply by checking if the second parameter passed is a string.

```
@field('text')
@field('text', 123)         // Returns the text field from post ID 123.
@field('image', 'url')      // If image is an array, returns the url value.
@field('image', 'url', 123) // If image is an array, returns the url value for post ID 123.
```

#### @hasfield

[](#hasfield)

`@hasfield` is a simple conditional checking if the specified field returns a value. Similar to `@field`, it accepts parameters to check array values as well as the post ID in the event you need your conditional to be specific. It can be closed using `@endfield`.

```
@hasfield('list')

    @fields('list')
      @sub('item')
    @fields

@endfield

@hasfield('image', 'url')

@endfield
```

#### @isfield

[](#isfield)

`@isfield` is a simple conditional for checking if your field value equals a specified value. As a third parameter, it accepts a post ID. It can be closed using `@endfield`.

```
@isfield('cta_type', 'phone')

@endfield

@isfield('cta_type', 'phone', 123)

@endfield
```

#### @fields

[](#fields)

`@fields` acts as a helper for handling repeater fields. It is wrapped with a [`have_rows()`](https://www.advancedcustomfields.com/resources/have_rows/) conditional, and if it returns true, begins the while loop followed by `the_row()`. It can be closed using `@endfields`.

```

  @fields('list')
    @sub('item')
  @endfields

```

Optionally, it can be passed a post ID:

```
@fields('list', 123)
  [...]
@endfields
```

#### @sub

[](#sub)

`@sub` does what you would expect it to do and echo's the specified sub field using [`get_sub_field()`](https://www.advancedcustomfields.com/resources/get_sub_field/). It is to be used inside of repeatable fields such as `@fields`, `@layout`, `@group`, and `@options`.

Similar to `@field`, it can also accept a second parameter allowing you to return a value if the sub field is an array. More examples of `@sub` can be found within' the repeatable field examples listed above.

```

  @fields('list')
    @sub('item')
  @endfields

  @fields('slides')

  @endfields

```

#### @hassub

[](#hassub)

`@hassub` is a simple conditional checking if the specified sub field returns a value.

Similar to `@hasfield`, it also accepts a second parameter to check an array value. It can be closed using `@endsub`.

```
@hassub('icon')

@endsub

@hassub('image', 'url')

@endsub
```

#### @issub

[](#issub)

`@issub` is a simple conditional for checking if your sub field equals a specified value. It can be closed using `@endsub`.

```
@issub('icon', 'arrow')

@endsub
```

#### @layouts

[](#layouts)

`@layouts` acts as a helper for handling flexible content fields. Under the hood, it is essentially the exact same as `@fields`, but is provided to allow for a more clean, readable code-base in conjunction with `@layout` which calls `get_row_layout()`.

As with `@fields`, it accepts a post ID as a second parameter. It can be closed using `@endlayouts`.

```
@layouts('components')
  [...]
@endlayouts

@layouts('components', 123)
  [...]
@endlayouts
```

#### @layout

[](#layout)

`@layout` serves as a conditional checking if `get_row_layout()` equals the specified value during the `have_rows()` while loop.

Using `@layouts`, this allows you to have a rather clean view when displaying your flexible content components. It can be closed using `@endlayout`.

```
@layouts('components')
  @layout('card')

      @hassub('image')

      @endsub

        @sub('title')
        @sub('description')

  @endlayout

  @layout('button')
    @hassub('url')

        @hassub('icon')

        @endsub
        @sub('label')

    @endsub
  @endlayout

  @layout('content')
    @hassub('content')

        @sub('content')

    @endsub
  @endlayout
@endlayouts
```

#### @group

[](#group)

`@group` acts as a helper for handling group fields. Under the hood, it is essentially the exact same as `@fields` and thus serves as a simple alias for code readability purposes. Which one you prefer is entirely up to you. It can be closed using `@endgroup`.

```
@group('button')
  @hassub('url')

      @sub('label')

  @endsub
@endgroup
```

#### @option

[](#option)

`@option` echo's the specified theme options field using `get_field($field, 'option')`. As with the other field directives, it accepts a second parameter allowing you to retrieve a value if the option field returns an array.

```
Find us on Facebook

```

#### @hasoption

[](#hasoption)

`@hasoption` is a simple conditional checking if the specified theme option field returns a value. It can be closed using `@endoption`.

```
@hasoption('facebook_url')
  Find us on Facebook
@endoption
```

#### @isoption

[](#isoption)

`@isoption` is a simple conditional for checking if your theme option field equals a specified value. It can be closed using `@endoption`.

```
@isoption('logo_type', 'svg')
  [...]
@endoption
```

#### @options

[](#options)

`@options` acts as a helper for handling repeater and group fields within' your theme options. Under the hood, it is essentially the exact same as `@fields` except it automatically has the theme options ID `'option'` passed to it. It can be closed using `@endoptions`.

```
@hasoption('social')

    @options('social')

          @hassub('icon')

          @endsub
          @sub('platform')

    @endoptions

@endoption
```

### Helpers

[](#helpers)

The following directives are generalized helpers in an attempt to avoid using `@php` and `@endphp` where it isn't absolutely necessary.

#### @condition

[](#condition)

`@condition` is a simple `if` condition that checks the first parameter passed, and if it equals true, echo's the value passed in the second parameter.

```
@if ($phone = App::phone())
  Call us at {{ App::phone() }}
@endif

  Visit our website

```

#### @global

[](#global)

`@global` global's the specified variable.

```
@global($post)
```

#### @set

[](#set)

`@set` sets the specifed variable to a specified value.

```
@set($hello, 'world')
```

#### @unset

[](#unset)

`@unset` unsets the specified variable.

```
@unset($hello)
```

#### @extract

[](#extract)

`@extract` extracts the passed array into variables. I find this particularly useful when I want to make my views customizable when passing parameters to `@include` but also having default values set within' the view.

```
// single.blade.php
@include('components.entry-meta', [
  'author' => false,
  'date'   => true,
])

// entry-meta.blade.php
@extract([
  'author' => $author ?? true,
  'date'   => $date   ?? true
])

@if ($author)
  [...]
@endif

@if ($date)
  [...]
@endif
```

#### @implode

[](#implode)

`@implode` echo's a string containing a representation of each element within' the array passed to it with a glue string between each element.

```
@implode(', ' ['dog', 'cat', 'mouse', 'snake'])
// dog, cat, mouse, snake
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 57.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Total

7

Last Release

2632d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3eb68ef9c0ba492267248a9d5b31837d41aba4942a3e8a26d87ff8a8e5297d50?d=identicon)[dawidurbanski](/maintainers/dawidurbanski)

---

Top Contributors

[![Log1x](https://avatars.githubusercontent.com/u/5745907?v=4)](https://github.com/Log1x "Log1x (11 commits)")[![dawidurbanski](https://avatars.githubusercontent.com/u/12466568?v=4)](https://github.com/dawidurbanski "dawidurbanski (7 commits)")[![thomasbrunier](https://avatars.githubusercontent.com/u/10458344?v=4)](https://github.com/thomasbrunier "thomasbrunier (1 commits)")

---

Tags

wordpressbladerootssage

### Embed Badge

![Health badge](/badges/dawidurbanski-sage-directives/health.svg)

```
[![Health](https://phpackages.com/badges/dawidurbanski-sage-directives/health.svg)](https://phpackages.com/packages/dawidurbanski-sage-directives)
```

###  Alternatives

[log1x/sage-directives

A set of Blade directives for use with Roots Sage.

297709.3k5](/packages/log1x-sage-directives)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[log1x/blade-svg-sage

Composer package to add support for Blade SVG by Adam Wathan to Roots Sage.

7577.3k](/packages/log1x-blade-svg-sage)[log1x/sage-html-forms

Create forms using HTMLForms.io and Sage 10 Blade components

5636.1k](/packages/log1x-sage-html-forms)[roots/wp-blade-check

Simple Composer package that checks and displays an admin notice if your uncompiled Blade templates are publicly accessible.

161.1k](/packages/roots-wp-blade-check)[hexbit/sage-woocommerce

Woocommerce support for sage 10

257.0k](/packages/hexbit-sage-woocommerce)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
