nystudio107 / craft-seomatic

SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.
https://nystudio107.com/plugins/seomatic
Other
162 stars 68 forks source link

How to update frontendTemplatesContainer via content migration #1465

Closed jrrdnx closed 1 month ago

jrrdnx commented 1 month ago

Updating a few settings via a content migration and have most of them working, e.g.:

$globalMetaBundle = Seomatic::$plugin->metaBundles->getGlobalMetaBundle(Craft::$app->sites->getPrimarySite()->id);

$globalMetaBundle->metaGlobalVars->siteNamePosition = 'after';
$globalMetaBundle->metaSiteVars->creator->genericName = 'Sample Name';

Seomatic::$plugin->metabundles->updateMetaBundle($globalMetaBundle, Craft::$app->sites->getPrimarySite()->id);

Unfortunately I'm having trouble updating the default robots template via:

$globalMetaBundle->frontendTemplatesContainer->data['robots']->setAttributes([
    'include' => 1,
    'templateString' => 'sample string'
]);

This particular method doesn't seem to have any affect. Any help would be greatly appreciated, thanks!

khalwat commented 1 month ago

Not sure, that looks right to me -- did you confirm that it's changed in the seomatic_metabundles table as expected after you've saved it?

jrrdnx commented 1 month ago

Confirmed it was an issue with the string I was attempting to save. The syntax I was using was working correctly. All good here, thanks!