Skip to main content
All CollectionsPersonal websitesStatamic
Statamic: publishing to multiple collections
Statamic: publishing to multiple collections

Enable StoryChief to publish articles to multiple Statamic collections.

Gregory Claeyssens avatar
Written by Gregory Claeyssens
Updated over 6 months ago

By default StoryChief will publish to your default collection, using the default blueprint and the mapping defined in config/storychief.php.
​

The following article explains how to set up publishing to multiple collection types/blueprints and mapping.

Before you get started


Set up the publishing to multiple collections

Step 1. Create a custom field of type "single option" on StoryChief where you can select your collection type.

Add options and set a label and description making it clear for your case.
See the example below.

Step 2. Configure your Statamic website to change collection, blueprint and/or mapping based on the custom field value we created in Step 1.

⚠️ Caution: The following should be done by your developer.

Inside App\Providers\AppServiceProvider.php register a custom implementation for the storychief_config facade.

<?php namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
// Register a new binding for the facade
app()->bind('storychief_config', function () {
return new \App\Facades\CustomStoryChiefConfig();
});
}

...

Step 3. Create the CustomStoryChiefConfig() class where you can change the collection, blueprint and mapping based on the incoming $payload.

<?php namespace App\Facades;

use Statamic\Support\Arr;
use StoryChief\StoryChief\Helpers\Configuration as StoryChiefConfig;

class CustomStoryChiefConfig extends StoryChiefConfig
{
public function set(array $payload): void
{
// Find the custom field in the $payload
$collectionCustomField = Arr::first(
$payload['data']['custom_fields'] ?? [],
function($field){
return (isset($field['key']) && $field['key'] === 'MY_CUSTOM_FIELD_KEY');
}
);

if(
$collectionCustomField &&
$collectionCustomField['value'] === 'news'
){
config()->set('storychief.collection', 'news');
config()->set('storychief.blueprint', 'newsitem');
config()->set('storychief.mapping', [
'title' => 'title',
'content' => 'body',
]);
}
}
}

πŸŽ‰ You're done, grab a coffee, you deserve it!

Check out the next steps below for more in-depth guides or follow-up actions


πŸ“š Next steps

Did this answer your question?