Skip to content

Access your Statamic data via Blade directives, currently @bard, @collection & @Globalset supported

License

Notifications You must be signed in to change notification settings

radovanobal/statamic-blade

 
 

Repository files navigation

Blade Directives

MIT Licensed

This package provides custom directives so you can easily access Statamic data in your Blade templates.

Requirements

  • PHP 7.4+
  • Statamic v3

Installation

You can install this package via composer using:

composer require edalzell/blade-directives

The package will automatically register itself.

Usage

Collection

@collection('pages', ['where' => 'title:My Title,author:Erin', 'limit' => 3, 'orderBy' => 'title:desc'])
    {{ $entry['title'] }}
@endcollection

Data

Use this when you have Statamic data but it's a Value object. This will return a keyed array with all the fields as string/ints/arrays (recursively).

@data($theValueObject')
    {{ $fieldYouWant }}
@enddata

Entry

Gets all the data in an entry. In the example below the data is a replicator, so you have to walk through the sets.

@entry('the_collection_handle', 'entry-slug')
    @foreach($replicator as $set)
        <p>Type is {{ $set['type'] }}</p>
        @include("partials/{$set['type']}", $set)
    @endforeach
@endentry

Globals

@globalset('footer')
    {{ $set_variable }}
@endglobalset

@globalset('footer', 'set_variable')

Nav

@nav('footer')
    {{ $item['title'] }}
@endnav

You can use the same parameters as the nav tag.

@nav('collection::pages', ['from' => '/', 'show_unpublished' => true, 'include_home' => true])
    {{ $item['title'] }}
@endnav

Site

@site
    {{ $short_locale }}
@endsite
@site('short_locale')

Taxonomy

@taxonomy('tags')
    <p>Title is {{ $term['title'] }}</p>
@endtaxonomy

Testing

Run the tests with:

vendor/bin/phpunit

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

About

Access your Statamic data via Blade directives, currently @bard, @collection & @Globalset supported

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%