官术网_书友最值得收藏!

Creating the Blade template engine

Now, it's time to create another view component. This time, we will use the Blade template engine to show some records from our database. Let's look at what the official documentation says about Blade:

Blade is the simple, yet powerful, templating engine provided with Laravel. Unlike other popular PHP templating engines, Blade does not restrict you from using plain PHP code in your views. All Blade views are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application.

Now, it's time to see this behavior in action:

  1. Go back to the code editor and create another folder inside resources/views, called bands.
  2. Create a file, show.blade.php, inside resources/views/bands, and place the following code in it:
<h1>Band {{ $band->id }}</h1>
<ul>
<li>band: {{ $band->name }}</li>
<li>description: {{ $band->description }}</li>
</ul>
You can find out more about Blade at  https://laravel.com/docs/5.2/blade.
  1. Open your browser to http://localhost:8081/bands/1. You will see the template in action, with results similar to the following:
View of the template engine

Note that here, we are using the Blade template engine to show a record from our database. Now, let's create another view to render all of the records.

  1. Create another file, called index.blade.php, inside resources/views/bands, and place the following code in it:
@foreach ($bands as $band)
<h1>Band id: {{ $band->id }}</h1>
<h2>Band name: {{ $band->name }}</h2>
<p>Band Description: {{ $band->description }}</p>
@endforeach
  1. Go back to your browser and visit http://localhost:8081/bands/, where you will see a result similar to the following:
View template engine
主站蜘蛛池模板: 枣庄市| 吉安市| 封开县| 托克托县| 修文县| 鄂伦春自治旗| 类乌齐县| 奉贤区| 北海市| 探索| 武清区| 舟山市| 房产| 乡宁县| 卢湾区| 通榆县| 宝丰县| 鄱阳县| 延吉市| 白沙| 二手房| 科技| 建水县| 开封县| 乌兰浩特市| 达拉特旗| 特克斯县| 东平县| 阜平县| 乡城县| 抚州市| 双辽市| 渭源县| 浦县| 文化| 襄城县| 宜兰市| 怀化市| 恭城| 邵阳县| 筠连县|