0

I have in database template for email with variables ant etc.. When I pass that template in my view from database variable are not rendered and displayed {{ $child_fullname }}, {{ $specialist_fullname }} and etc. instead of given name.

Here is my Mail build function:

public function build()
{
    return $this->subject('Pranešimas apie sėkmingą registraciją')
                ->view('email-template')
                ->with([
                    'body'                => EmailTemplate::find(1)->text,
                    'child_fullname'      => $this->child->name . ' ' . $this->child->surname,
                    'specialist_fullname' => $this->card->specialist->name,
                    'date_time'           => $this->visits->workSchedule->work_date . 
                                             ' ' . $this->visits->workSchedule->work_time
                ]);
}

Blade template:

<!doctype html>
<html>
    <head>
        <meta name="viewport" content="width=device-width">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    {!! $body !!}
</html>

Result: enter image description here

Thanks in advance for help!

P.S Using this to send email.

3
  • Are you using markdown for your e-mail? Commented Nov 27, 2018 at 12:13
  • Nope. I'm not using markdown Commented Nov 27, 2018 at 12:17
  • If anybody faces same problem. Fixed using this solution: stackoverflow.com/a/33872239/2414450 Commented Nov 27, 2018 at 13:21

2 Answers 2

2

It's not rendering because body is a variable passed to the view.

You should first render the body, then include it into your e-mail.

One solution is to use https://github.com/TerrePorter/StringBladeCompiler it will get you started.

The pseudocode for it is:

public function build()
{
    return $this->subject('Pranešimas apie sėkmingą registraciją')
        ->view('email-template')->with(
            [
                'body'                  => renderFromString(EmailTemplate::find(1)->text, 
                [
                    'child_fullname'        => $this->child->name . ' ' . $this->child->surname,
                    'specialist_fullname'   => $this->card->specialist->name,
                    'date_time'             => $this->visits->workSchedule->work_date . ' ' . $this->visits->workSchedule->work_time
            ])
        );
}
Sign up to request clarification or add additional context in comments.

1 Comment

It doesn't support Laravel 5.7 version :/. When installing I get an error. wpb/string-blade-compiler 3.6 requires laravel/framework 5.6.* -> satisfiable by laravel/framework[5.6.x-dev].
0

Try Blade::compileString()

{!! Blade::compileString($body) !!}

1 Comment

Not working. Now shows nothing instead of variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.