Streams Plugin

Addons

addon

The addon function returns a decorated addon instance or null if not found. The identifier argument can be a dot notation namespace or unique slug.

{{ addon('anomaly.module.users').name }}
// Users Module

{{ addon('pages').namespace('settings') }}
// anomaly.module.pages::settings

addons

The addons method returns a decorated collection of addons. An optional type argument will restrict the type of addon returned.

{{ addons() }} // All addons.

// All enabled modules.
{% for module in addons('modules').enabled() %}
    <p>{{ module.name }} is enabled.</p>
{% endfor %}

User Agent

agent_is

The agent_is function returns if the agent matches a given string.

{% if agent_is("iPhone") %}
	<p>Sweet iPhone bro.</p>
{% endif %}

agent_is_mobile

The agent_is_mobile function returns whether the user agent is a mobile browser or not.

{% if agent_is_mobile() %}
	{{ asset_style('theme::mobile.css') }}
{% endif %}

Assets

asset_add

Adds an asset to a collection. An optional array of flags is also available.

{{ asset_add("theme.js", "theme::js/vendor/*", ["min"]) }}

asset_script

The asset_script function returns the script tag to the given collection.

{{ asset_script("theme.js", ["min"]) }}

asset_scripts

The asset_scripts function returns an array of script tags for the assets within a given collection.

{% for script in asset_scripts("scripts.js", ["min"]) %}
    {{ script|raw }}
{% endfor %}

constants

The constants function returns a script tag containing a number of often required javascript constants necessary for field types and potentially other components to work correctly. Make sure you include it in your themes!

{{ constants() }}

Learn more about JS constants.

Authorization

auth_check

The auth_check function returns whether a user is logged in or not.

{% if auth_check() %}
    Hello {{ auth_user().display_name }}!
{% endif %}

auth_guest

The auth_guest function returns the opposite of auth_check.

{% if auth_guest() %}
    <a href="{{ url_route('lgoin') }}">Login</a>
{% endif %}

Theming

Breadcrumb

The breadcrumb function renders a Bootstrap breadcrumb.

{{ breadcrumb() }}

You can use this function as an array to generate your own breadcrumb:

<ol class="breadcrumb">
    {% for breadcrumb, url in breadcrumb() %}
        {% if loop.last %}
            <li class="breadcrumb-item active">{{ trans(breadcrumb) }}</li>
        {% else %}
            <li class="breadcrumb-item"><a href="{{ url }}">{{ trans(breadcrumb) }}</a></li>
        {% endif %}
    {% endfor %}
</ol>

favicons

The favicons function renders multiple favicon tags based on a single source.

You can use this function to automatically generate comprehensive and modern favicon tags:

{{ favicons('theme::img/favicon.png') }}

The above function will generate the below favicons using the streams::partials/favicons view:

<link rel="icon" type="image/png" href="{{ image(source).resize(16, 16).path }}" sizes="16x16"/>
<link rel="icon" type="image/png" href="{{ image(source).resize(32, 32).path }}" sizes="32x32"/>
<link rel="icon" type="image/png" href="{{ image(source).resize(96, 96).path }}" sizes="96x96"/>
<link rel="icon" type="image/png" href="{{ image(source).resize(128, 128).path }}" sizes="128x128"/>
<link rel="icon" type="image/png" href="{{ image(source).resize(196, 196).path }}" sizes="196x196"/>
<link rel="apple-touch-icon-precomposed" sizes="57x57" href="{{ image(source).resize(57, 57).path }}"/>
<link rel="apple-touch-icon-precomposed" sizes="60x60" href="{{ image(source).resize(60, 60).path }}"/>
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="{{ image(source).resize(72, 72).path }}"/>
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="{{ image(source).resize(76, 76).path }}"/>
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="{{ image(source).resize(114, 114).path }}"/>
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="{{ image(source).resize(120, 120).path }}"/>
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="{{ image(source).resize(144, 144).path }}"/>
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="{{ image(source).resize(152, 152).path }}"/>

Miscellaneous

carbon

The carbon function provides access to Carbon.

{{ carbon().today() }}
// 2016-06-24 00:00:00

{{ carbon('-1 day', config('app.timezone')) }}
// "2016-08-17 15:05:26"

{{ carbon('-1 day', config('app.timezone')).diffInHours() }}
// 24

Currency

currency_format

The currency_format function returns the number in currency format proceeded by the system configured currency symbol.

You may also specify an optional currency code to use specifically. The system configured currency will be used by default.

Lastly you can specify an array of options to change configured behavior. Available options are direction, separator, decimals, and point.

{{ currency_format(number) }}
{{ currency_format(number, currency) }}
{{ currency_format(number, currency, options) }}

// Sum up the "amount" of a collection of entries.
// Assuming "amount" is an integer field type.
{{ currency_format(payments.sum('amount.value')) }}
// $12,712.93

currency_normalize

The currency_normalize function returns the number in currency format without the system configured currency symbol.

You may also specify an optional currency code to use specifically. The system configured currency will be used by default.

Lastly you can specify an array of options to change configured behavior. Available options are direction, separator, decimals, and point.

{{ currency_normalize(number) }}
{{ currency_normalize(number, currency) }}
{{ currency_normalize(number, currency, options) }}

// Sum up the "amount" of a collection of entries.
// Assuming "amount" is an integer field type.
{{ currency_normalize(payments.sum('amount.value'), 'USD', {'separator': ''}) }}
// 12712.93

CSRF

csrf_token

The csrf_token function returns the CSRF token value.

{{ csrf_token() }}
// Uge4akcwu7HyGLEeJ3uJseqUCRxk9Yz6B7Yi0kkG

csrf_field

The csrf_field function returns the name of the CSRF field.

{{ csrf_field() }}
// <input type="hidden" name="_token" value="Uge4akcwu7HyGLEeJ3uJseqUCRxk9Yz6B7Yi0kkG">

Entries

entries

The entries function provide you with a convenient, fluent interface to fetch stream entries.

<ul>
    {% for category in entries('posts', 'categories').get() %}
    <li>
        {{ category.slug }}
    </li>
    {% endfor %}
</ul>

You can interact with entries before firing get just like you would a query builder.

{% set products = entries('store', 'products')
	.where('featured', true)
	.order_by('rating','DESC')
	.get() %}

<ul>
    {% for product in products %}
    <li>
        {{ product.name }}
    </li>
    {% endfor %}
</ul>

The entry criteria is extendable! To learn how to add your own functionality to queries refer to the criteria documetation.{.tip}

query

The query function aids in fetching database records that are not streams.

{% set jobs = query()
    .from('failed_jobs')
    .orderBy('failed_at', 'DESC'
    .get() %}

You can also provide a model to use instead of specifying with from(table):

{% set users = query('App\Example\TestModel')
	.where('active', true)
	.orderBy('failed_at', 'DESC'
	.get() %}

In order to leverage model criteria you must provide a model.{.notice}

Environment

env

You can access environmental variable values with the env function. This function behaves just like the Laravel helper function.

{% if env(key, default) %}
	True
{% endif %}

{% if env("APP_DEBUG") %}
    You are debugging!
{% endif %}

Footprint

request_time

The request_time function returns the elapsed time in seconds for the request. You can optionally specify the number of decimals to return. The default is 1.

{{ request_time(3) }}
// 0.551

memory_usage

The memory_usage function returns the memory used by the request. You can optionally specify the number of decimals to return. The default is 1.

{{ memory_usage(2) }}
// 6.51 m

Images

Learn more about working with images.

img

The img function returns an image instance with <img> as the default output method.

{{ image('theme::img/logo.png')|raw }}
// <img src="/app/default/assets/addons/default/mysite/example-theme/resources/images/logo.png?v=1549566000" alt="Logo">

You can fluently chain methods together to manipulate the image:

{{ image('theme::img/logo.png').resize(1000).quality(60)|raw }}
// <img src="/app/default/assets/addons/default/mysite/example-theme/resources/images/082f74498bc34c1f37fbd56818417350.png?v=1549566000" alt="Logo">

You can also specify alternate output methods:

<img src="{{ image('theme::img/logo.png').path }}">
// /app/default/assets/addons/default/anomaly/example-theme/resources/images/logo.png?v=1549566000

<img src="{{ image('theme::img/logo.png').height(95).inline|raw }}">
// <img alt="Logo" height="95" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMcAAABfCAYAAABcMNP=">

Requests

request

The request function returns the request object. For example you can get the route's id parameter like this:

{{ request().route('id') }}
// 123

request_get

The request_get function returns $_GET parameters from the request.

{{ request_get(parameter, default) }}

request_method

The request_method function returns the request's method verb.

{% if request_method() == 'GET' %}
	<p>Lemme GET that for you.</p>
{% endif %}

request_root

The request_root function returns the request root.

{{ request_root() }}
// http://domain.com/

request_path

The request_path function returns the request path.

{{ request_path() }}
// /the/uri/path

request_segment

The request_segment function returns the specified URI segment.

{{ request_segment(1) }}
// admin

request_is

The request_is function returns if the request path matches a pattern. If multiple patterns are provided then true will be returned if any match.

{{ request_is("myaccount/*", "account/*") }}
// true or false

request_ajax

The request_ajax function whether or not the request is ajax.

{{ request_ajax() }}
// true or false

Session

session_get

The session_get function returns a value from session.

{{ session_get(key) }}
{{ session_get(key, default) }}

session_pull

The session_pull function returns and removes a value from session.

{{ session_pull(key) }}
{{ session_pull(key, default) }}

session_has

The session_has function returns whether the session has a value by key or not.

{% if session_has(key) %}
	<p>Party in da house!</p>
{% endif %}

Strings

Learn more about working with strings.

str_humanize

The str_humanize function returns the humanized version of a string. The separator is - by default. This is a common way to transform slugs into human readable names.

{{ str_humanize(string, separator) }}

str_truncate

The str_truncate function returns a truncated string of a given length while preserving words. The end argument defaults to ....

{{ str_truncate(string, length, end) }}

str_is

The str_is function returns whether or not the provided string matches the pattern. You can use * in your pattern as a wildcard.

{% if str_is(pattern, string) %}
    <p>The pattern matches!</p>
{% endif %}

str_camel

The str_camel function returns the camel case version of a string.

{{ str_camel(string) }}

str_studly

The str_studly function returns the studly cased version of a string.

{{ str_studly(string) }}

str_random

The str_random function returns a random string. The length argument defaults to 16.

{{ str_random(10) }}

Localization

trans

The trans function returns the translated string from a key.

{{ trans("anomaly.module.users::addon.name") }}
// Users Module

You can optionally provide an array of data to replace in the string as well as a locale. The current locale will be used by default.

{{ trans(key, replace, locale) }}

trans_has

The trans_has function returns whether or not the given translation key exists. You may also specify an optional locale. The current locale will be used by default.

{{ trans_has(key) }}
{{ trans(key, locale) }}

URLs

Learn more about URL generation.

url

The url function returns an absolute URL to a given path. An array of extra parameters may be passed to build a query string. Lastly a secure flag (true or false) may also be used to force HTTPS in the generated URL. Your current request protocol will be used by default.

{{ url(path) }}
{{ url(path, extra) }}
{{ url(path, extra, secure) }}

url_secure

The url_secure function returns an absolute URL to a given path while forcing HTTPS. An array of extra parameters may be passed to build a query string.

{{ url_secure(path) }}
{{ url_secure(path, extra) }}

url_route

The url_route function returns the URL to a given named route. An array of extra parameters may be passed to build a query string and replace variables in the route path. Lastly a secure flag (true or false) may also be used to force HTTPS in the generated URL. Your current request protocol will be used by default.

{{ url_route(path) }}
{{ url_route(path, extra) }}
{{ url_route(path, extra, secure) }}

Views

view

The view function returns a rendered view. This method is similar to Twig's include tag.

{{ view(view) }}

You may also pass an array of data to use within the specified view.

{{ view('example.module.test::example/view', {'foo': 'Bar'}) }}

parse

The parse function parses a string as a template.

{{ parse(template) }}

You may also pass an array of data to use within the specified template.

{{ parse("This is a template {{ foo }}", {"foo": "bar"}) }}

This can be helpful if you need to render content from something like a textarea value.

{{ parse(entry.simple_content.value) }}

value

The value function value parses a string for an entry.

{{ value(parameters, entry) }}

layout

The layout method checks for and returns a theme layout or returns the default if it's not found. The default layout is theme::layouts/default by default.

{% extends layout(layout) %}
{% extends layout(layout, default) %}

Most modules specify a layout named after the addon and default normally. This way if it exists great, otherwise use the default layout which always exists.

{% extends layout('posts') %}