英文:
How to use Laravel Markdown in View blade template
问题
我的主要目标是获取视图文件的原始HTML输出,然后将其发送到外部API(Zoho)以处理电子邮件。
我有一个位于/resources/views/emails/welcome.blade.php
的文件(该文件没有Mailable类),并且我有以下代码,它提取文件的原始HTML(使用view()->render()
):
$to = [
'user_name' => 'Test',
'email' => 'xxx@email.com'
];
$mail = [
'to' => $to,
'lines' => ['Test 1', 'Test 2']
];
$data = [
'to' => [$to],
'mail_format' => 'html',
'content' => view('emails.welcome', compact('mail'))->render()
];
$payload = $this->payload([$data]);
但是,我希望在welcome.blade.php
上使用Markdown,我尝试使用其他电子邮件模板上看到的<x-mail:message>
,如下面的代码,但它抛出错误**未为[mail]定义提示路径。
**:
<x-mail::message>
# Hi {{ $mail['to']['user_name'] }}
{{-- Lines --}}
@foreach ($mail['lines'] as $line)
{!! $line !!}
@endforeach
Thanks,<br>
{{ config('app.name') }}
</x-mail::message>
如果我直接将内容添加到文件中,Markdown标记不起作用。
感谢任何帮助
英文:
My primary goal was to grab the raw html output of the view file to send to an external API (Zoho) to process the email.
I have a file in /resources/views/emails/welcome.blade.php
(there is no Mailable class for that file)
and I have this code below which pulls the raw html of the file ( using view()->render()
)
$to = [
'user_name' => 'Test',
'email' => 'xxx@email.com'
];
$mail = [
'to' => $to
'lines' => ['Test 1', 'Test 2']
];
$data = [
'to' => [$to],
'mail_format' => 'html',
'content' => view('emails.welcome', compact('mail'))->render()
];
$payload = $this->payload( [$data] );
However, I want to use markdown on the welcome.blade.php
, I tried using the <x-mail:message>
I've seen on other email template like the code below, but its throwing an error No hint path defined for [mail].
<x-mail::message>
# Hi {{ $mail[to]['user_name'] }}
{{-- Lines --}}
@foreach ($mail['lines'] as $line)
{!! $line !!}
@endforeach
Thanks,<br>
{{ config('app.name') }}
</x-mail::message>
and if I add the content directly in the file, the markdown tagging does not work
appreciate any help
答案1
得分: 1
这是未经测试的,我尝试在本地使Markdown工作,它有效,你可以测试一下(不要忘记在你的类顶部添加 use Illuminate\Mail\Markdown
):
use Illuminate\Mail\Markdown;
...
$to = [
'user_name' => 'Test',
'email' => 'xxx@email.com'
];
$mail = [
'to' => $to,
'lines' => ['Test 1', 'Test 2']
];
$markdown = app(Markdown::class);
$data = [
'to' => [$to],
'mail_format' => 'html',
'content' => $markdown->render('emails.welcome', compact('mail'))->toHtml()
];
$payload = $this->payload([$data]);
希望这有帮助!
英文:
This is untested, I tried to make the Markdown work on my local and it works, can you test this out (don't forget to put use Illuminate\Mail\Markdown
at the top of your class):
use Illuminate\Mail\Markdown;
...
$to = [
'user_name' => 'Test',
'email' => 'xxx@email.com'
];
$mail = [
'to' => $to
'lines' => ['Test 1', 'Test 2']
];
$markdown = app(Markdown::class);
$data = [
'to' => [$to],
'mail_format' => 'html',
'content' => $markdown->render('emails.welcome', compact('mail'))->toHtml()
];
$payload = $this->payload( [$data] );
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论