Getting Started
Favicon Generation
Web Manifest
Metadata
Site Essentials for Statamic attempts to locate data from various locations within your template's context, depending on the precise tag being built. Almost all builder methods can have their values customized.
The simplest way to customize the data made available to the builder methods is to specify a callback function when calling the method. For example, the following would return Stillat
when on the homepage, or add a specific entry's title to the beginning of the generated title:
1<?php 2 3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata; 4 5Metadata::general()->title(function (array $context) { 6 if ($context['is_homepage']) { 7 return 'Stillat'; 8 } 9 10 $title = $context['title'] ?? null;11 12 if (! $title || $title === 'Stillat') {13 14 return 'Stillat';15 }16 17 return "{$title} | Stillat";18});
Callback functions will receive the se_meta
tag's context at the point it was evaluated in your template. Some built-in providers define default variables. This is done by providing a string value starting with a $
symbol. For example, the title
builder method is implemented like this:
1<?php 2 3// ... 4 5public function title($title = '$title'): self 6{ 7 $this->getManager()->queue([ 8 '_template' => '<title>{{ title }}</title>', 9 'title' => $this->value($title),10 ]);11 12 return $this;13}
We can tap into the $title
variable by using the Metadata
facade's resolve method:
1<?php 2 3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata; 4 5Metadata::resolve('title', function (array $context) { 6 if ($context['is_homepage']) { 7 return 'Stillat'; 8 } 9 10 $title = $context['title'] ?? null;11 12 if (! $title || $title === 'Stillat') {13 return 'Stillat';14 }15 16 return "{$title} | Stillat";17});
Using the Metadata::resolve
method is much simpler when interacting with metadata builder methods that register multiple meta/link tags at once, such as the withDefaults
method.
The following table lists the various builder methods that have default variables:
Builder | Method | Variable Name |
---|---|---|
General | title |
|
General | self |
|
General | description |
|
General | keywords |
|
General | author |
|
General | canonical |
|
General | first |
|
General | last |
|
General | prev |
|
General | next |
|
Open Graph | title |
|
Open Graph | url |
|
Open Graph | description |
|
Open Graph | siteName |
|
The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.