Home  >  Article  >  PHP Framework  >  Detailed explanation of Laravel Blade template one-time components @once

Detailed explanation of Laravel Blade template one-time components @once

藏色散人
藏色散人forward
2020-08-26 13:12:262354browse

The following is a tutorial column to introduce you to the Detailed explanation of Laravel Blade template one-time components @once Blade template one-time component @once, I hope it will be helpful to friends who need it!

In Detailed explanation of Laravel Blade template one-time components @once 7.25 version, Blade has added a new component

@onceDetailed explanation of Laravel Blade template one-time components @once. This component is used to render a single tag. This may not be easy to understand. Let’s illustrate it through an example: pull request:

组件内容如下

@once
    <script>
       无论该组件被渲染多少次,在模板中你只会看到一次输出。
    </script>
@endonce

The following is another example provided by Mohamed:<pre class="brush:php;toolbar:false;">@once &lt;template id=&quot;recieptsTemplate&quot;&gt; &lt;p class=&quot;flex flex-column items-center&quot;&gt; &lt;p class=&quot;w-1/2&quot; data-reciept=&quot;paid_at&quot;&gt;&lt;/p&gt; &lt;p class=&quot;w-1/4&quot; data-reciept=&quot;amount&quot;&gt;&lt;/p&gt; &lt;/p&gt; &lt;/template&gt; @endonce &lt;p data-id=&quot;receipts&quot; class=&quot;pide-y pide-grey-300&quot;&gt;&lt;/p&gt;</pre>

This is a receipt list. The receipt template only needs to be rendered once in the entire page, but the component itself can be called multiple times, which will not affect the receipt list structure.

You can use

once

directly in v7.25 and later Detailed explanation of Laravel Blade template one-time components @once versions.

Original address: https://laravel-news.com/laravel-blade-once-component

Translation address: https://learnku.com/laravel/t/ 48857

The above is the detailed content of Detailed explanation of Laravel Blade template one-time components @once. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete