第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Laravel 中將 Markdown 文本傳遞給 Markdown Blade?

如何在 Laravel 中將 Markdown 文本傳遞給 Markdown Blade?

PHP
慕尼黑8549860 2023-10-01 16:05:25
我需要在 Laravel 中發(fā)送 Markdown 電子郵件,但是該電子郵件的文本必須是可編輯的。當我傳遞$body到相關視圖時,它顯示如下:$body = '''# Introductionhi {{ $username }} The body of your {{ $family }}.@component('mail::button', ['url' => ''])Button Text@endcomponent'''在blade的相關視圖中:@component('mail::message')    {{ $body }}Thanks,<br>{{ config('app.name') }}@endcomponent這是輸出:有誰知道為什么會發(fā)生這種情況?
查看完整描述

3 回答

?
千萬里不及你

TA貢獻1784條經(jīng)驗 獲得超9個贊

您無需將其作為字符串傳遞,而是將整個主體放入已有的視圖刀片中,并包含上述所有變量,如下所示:


  @component('mail::message')

    

       hi {{ $username }} 

       The body of your {{ $family }}.


       @component('mail::button', ['url' => ''])

          Button Text

       @endcomponent

    

       Thanks,<br>

       {{ config('app.name') }}

    @endcomponent

然后,在發(fā)送郵件時,只需將所需的所有變量傳遞給該視圖即可。由于我不確定您如何發(fā)送電子郵件,以下是使用 Mailable 類的示例:


Mail::to('email_address')->send(new MailableClass($username, $family));

然后,您的 Mailable 類將如下所示:


public function __construct($username, $family)

    {

        $this->username = $username;

        $this->family = $family;

    }


    

    public function build()

    {

        $data['username'] = $this->username;

        $data['family'] = $this->family;


        return $this

            ->view('your_blade', $data)

            ->subject('Subject');

    }

然后,您的變量將顯示在給定的視圖中。


查看完整回答
反對 回復 2023-10-01
?
慕妹3242003

TA貢獻1824條經(jīng)驗 獲得超6個贊

只需將其更改為查看刀片:

{!! $body !!}


查看完整回答
反對 回復 2023-10-01
?
紅糖糍粑

TA貢獻1815條經(jīng)驗 獲得超6個贊

將 Markdown 內容作為變量傳遞到空 Blade 文件,但它不起作用。


我的 Mailable 類未處理刀片指令(例如@component)。


為什么?


看起來,在替換變量之前,render中的方法Illuminate\Mail\Markdown.php將替換 Blade 視圖文件中的郵件組件(按原樣)。


解決方法


并不理想,但現(xiàn)在我最終修改了一個實際文件(僅用作占位符)。


注意:您可能希望 git 忽略此文件,或更新回空。


class CampaignFormat extends Mailable

{

? ? protected $markdownContent;


? ? public function __construct($markdownContent)

? ? {

? ? ? ? $this->markdownContent = $markdownContent;

? ? }


? ? /**

? ? ?* Required, since it won't let me pass the content to the file as a string variable.

? ? ?* It expects to have the component directives directly on the actual blade file.

? ? ?*/

? ? const DYNAMIC_MARKDOWN_TEMPLATE_PATH = 'views/emails/dynamic_markdown_template.blade.php';


? ? /**

? ? ?* The render method invokes this one internally.

? ? ?*/

? ? public function build()

? ? {? ? ? ??

? ? ? ? $this->markdown('emails.dynamic_markdown_template')

? ? ? ? ? ? ->with('markdownContent', $this->markdownContent);

? ? }

? ??

? ? private function updateTemplateFileTemporarily()

? ? {

? ? ? ? // Update the file with the desired content

? ? ? ? File::put(resource_path(self::DYNAMIC_MARKDOWN_TEMPLATE_PATH), $this->markdownContent);? ?

? ? }

? ??

? ? private function clearTemplateFile()

? ? {

? ? ? ? // Clear the file so it doesn't keep changes

? ? ? ? File::put(resource_path(self::DYNAMIC_MARKDOWN_TEMPLATE_PATH), '');

? ? }


? ? /**

? ? ?* It does the magic.

? ? ?*/

? ? public function dynamicRender(): string

? ? {

? ? ? ? $this->updateTemplateFileTemporarily();

? ? ? ? $html = $this->render();

? ? ? ? $this->clearTemplateFile();

? ? ? ? return $html;

? ? }


}

就我而言,我只是使用它來獲取渲染的 HTML,并將其存儲到我的數(shù)據(jù)庫中。


我使用的電子郵件服務將負責將 HTML 批量發(fā)送給我的用戶。


查看完整回答
反對 回復 2023-10-01
  • 3 回答
  • 0 關注
  • 136 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號