Mity Docs Mity Docs for Mity Digital
Sitemapamic Documentation

Computed configuration

There may be times where you want the value of one of Sitemapamic's field mappings to be determined by some other field within your Entry's Blueprint.

Perhaps you're using a third-party SEO addon that has its own fields for determining something like including (or excluding) in your sitemap. Or you just have a specific way of needing to do something that needs a bit more of a unique processing.

This is where you can use computed values to provide Sitemapamic's configuration options. Check out Statamic's docs on computed values for full details.

Within one of your app's Service Providers you can define a computed value for one of Sitemapamic's field mappings:

  • meta_include_in_xml_sitemap

  • meta_change_frequency

  • meta_priority

Your computed values must be one of the field's expected options: you can see these from the Blueprint Requirements.

Example

Let's say that your meta_include_in_xml_sitemap value to be determined based on a robots field within your Blueprint. Within one of your Service Providers, you could include a definition for the meta_include_in_xml_sitemap:

1use Statamic\Entries\Entry;
2use Statamic\Facades\Collection;
3 
4Collection::computed(['pages', 'blog'], 'meta_include_in_xml_sitemap', function (Entry $entry) {
5 $robots = $entry->get('robots');
6 
7 if ($robots && in_array('noindex', $robots)) {
8 return 'false';
9 }
10 
11 return 'default';
12});

In this example, for the Entries in the Pages and Blog Collections, the meta_include_in_xml_sitemap value will be either false or default.

If the robots field value includes noindex, it will return false. Otherwise will return default.

This is just an example - but shows what a computed value definition could look like for your site.