Stills
Stills are exactly the same idea as query scopes, but for Distill queries. They let you give a reusable query a name, which you can then apply in the tag or use to drive a search index.
Creating Stills
To create one add a class to app/Stills. It needs an apply method that receives the query builder and the tag's parameters:
namespace App\Stills;
use JackSleight\StatamicDistill\Stills\Still;
class Videos extends Still
{
public function apply($query, $values)
{
$query->path('builder.*')->type('set:video');
}
}
Stills are discovered automatically. The handle is the snake cased class name, so this one is videos, or you can set your own with a protected static $handle property.
Applying Stills
Apply a still with the still parameter. More than one can be applied by separating them with a pipe, and any other parameters on the tag are applied as well. They're applied in turn, so a later still's type and path replace an earlier one's, while conditions add up:
{{ distill:page still="videos" limit="3" }}
{{ title }}
{{ /distill:page }}
The $values argument is the full set of tag parameters, so a still can read options of its own. When a still is run by the search indexer there are no parameters, so give them a default:
public function apply($query, $values)
{
$query->path('builder.*')->type('set:video');
if ($provider = $values['provider'] ?? null) {
$query->where('url', 'like', "%{$provider}%");
}
}