This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi,
Ive built a theme which has company_name, company_telephone variables etc. I want to use this data in emails. So i was planning on registering view::share() so that the email template can access these variables . However not sure how i access the theme variables in a component. in twig its this.theme.company_name.
thanks
use Cms\Classes\Theme;
and then call your variable with
Theme::getEditTheme()->your_variable
as defined in themes/your-theme/config/fields.yaml
Last updated
Speci>phplee said:
Ive built a theme which has company_name, company_telephone variables etc. I want to use this data in emails. So i was planning on registering view::share() so that the email template can access these variables
Here's an example - put it in a plugin's boot()
method:
App::before(function() {
Event::listen('mailer.beforeAddContent', function ($mailer, $message, $view, $data)
{
if ($actheme = \Cms\Classes\Theme::getActiveTheme())
{
$themedata = [];
$themailvars = explode(',', 'site_name,site_mail,site_phone');
foreach ($themailvars as $themailvar)
{
$themedata[$themailvar] = $actheme->{$themailvar};
}
View::share('theme', $themedata);
}
}, 5);
});
1-5 of 5