This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

phplee
phplee

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

phplee
phplee

Can anyone help me on this. I want the theme variables to be accessible in mail layouts

philou.savary24303
philou.savary24303

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

phplee
Eoler
Eoler

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

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.