jeudi 17 août 2023

after changing theme for one Mailable file in laravel it messup other email which dont have $theme variable set

below is my code to change the theme for particular emails where customize mailable is extended.

class TablerMailable extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Instruct to use tabler theme.
     *
     * @var string
     */
    public $theme = 'tabler';

    /**
     * Build the Markdown view for the message.
     *
     * @return array
     */
    protected function buildMarkdownView()
    {
        $markdown = Container::getInstance()->make(Markdown::class);
        $markdown->loadComponentsFrom([resource_path('views/vendor/tabler-mail')]);

        if (isset($this->theme)) {
            $markdown->theme($this->theme);
        }
        
        $data = $this->buildViewData();

        $views= [
            'html' => $markdown->render($this->markdown, $data),
            'text' => $this->buildMarkdownText($markdown, $data),
        ];
        
        return $views;
    }
}

my problem is other emails that don't extend this class also get affected by this change. I don't know how to unset this theme for those emails where the $theme variable is already not set.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire