Render CMS content in console command #2133
Unanswered
nadar
asked this question in
Questions & Problems
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Q:
i’m trying to achieve the following:
I want a console command that sends out mails on a daily basis.
The contents of the mails should be composed and edited via the CMS (i create a cms page for every mail) and then rendered inside the console command.
Is that even possible in console context? If yes, how do i access the cms contents?
This does not work and dies with a an exception:
Yii::$app->menu->findOne([‘id’ => $mailPageId);
Exception ‘yii\base\InvalidConfigException’ with message ‘Unknown component ID: composition’
A:
I have not tested, but i would suggest you to build your content and store in luya\Config.
To build the content you could catch the Yii2 afterUpdate event for model NavItemPage (https://github.com/luyadev/luya-module-cms/blob/master/src/models/NavItemPage.php) and then store the content in the config.
$model = NavItemPage ... from after event update hook
$content = $model->getContent();
\luya\Config::set('myNewsletterContent', $content);
Then in the console command you can grab the content with luya\Config::get('myNewsletterContent')
I have not tested, but this should work. Would be nice if you could post the final result here.
Beta Was this translation helpful? Give feedback.
All reactions