Download the PHP package dawidurbanski/sage-directives without Composer
On this page you can find all versions of the php package dawidurbanski/sage-directives. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dawidurbanski/sage-directives
More information about dawidurbanski/sage-directives
Files in dawidurbanski/sage-directives
Package sage-directives
Short Description A set of Blade directives for use with Roots Sage.
License MIT
Homepage https://github.com/dawidurbanski/sage-directives
Informations about the package sage-directives
Sage Directives
Sage Directives is a simple Composer package adding a variety of useful Blade directives for use with Sage 9.
Requirements
Installation
Install via Composer:
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 | ACF | Helpers | |
---|---|---|---|
@query | @fields | @layouts | @condition |
@posts | @field | @layout | @global |
@title | @hasfield | @group | @set |
@content | @isfield | @option | @unset |
@excerpt | @sub | @hasoption | @extract |
@shortcode | @hassub | @isoption | @explode |
@user | @issub | @options | @implode |
@guest |
WordPress
The following directives are specific to WordPress core functionality.
@query
@query
initializes a standard WP_Query
as $query
and accepts the usual WP_Query
parameters as an array.
@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()
.
If an instance of WP_Query
is passed to @posts
as a variable, it will use that instead.
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
simply echo's the current posts title using get_the_title()
. It can also accept a specific post as a parameter.
@content
@content
simply echo's the current posts content using the_content()
.
@excerpt
@excerpt
simply echo's the current posts excerpt using the_excerpt()
.
@shortcode
@shortcode
simply echo's the provided shortcode using do_shortcode()
.
@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
.
@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
.
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
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.
@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
.
@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
.
@fields
@fields
acts as a helper for handling repeater fields. It is wrapped with a have_rows()
conditional, and if it returns true, begins the while loop followed by the_row()
. It can be closed using @endfields
.
Optionally, it can be passed a post ID:
@sub
@sub
does what you would expect it to do and echo's the specified sub field using 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.
@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
.
@issub
@issub
is a simple conditional for checking if your sub field equals a specified value. It can be closed using @endsub
.
@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
.
@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
.
@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
.
@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.
@hasoption
@hasoption
is a simple conditional checking if the specified theme option field returns a value. It can be closed using @endoption
.
@isoption
@isoption
is a simple conditional for checking if your theme option field equals a specified value. It can be closed using @endoption
.
@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
.
Helpers
The following directives are generalized helpers in an attempt to avoid using @php
and @endphp
where it isn't absolutely necessary.
@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.
@global
@global
global's the specified variable.
@set
@set
sets the specifed variable to a specified value.
@unset
@unset
unsets the specified variable.
@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.
@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.