# view
[[toc]]
Views are just HTML, using Laravel's Blade templating engine, and Twig since Blessing Skin v5.
For more detailed usage of views, please refer to the Views (opens new window) section of the Laravel documentation.
For more detailed usage of Blade templates, please refer to the Blade Templates (opens new window) section of the Laravel documentation.
# Add view file
All view files are placed in the views
directory under the plugin
directory. If the suffix of the view file is .blade.php
, then use
Blade as the template engine; if the suffix of the view file is
.twig
, then use Twig as the template engine.
# use view
If you wish to return a view, you can use the global
view helper function in your controller
:
public function showLoginPage()
{
return view( 'Author\MyPlugin::hello.world' ) ;
}
Note that the namespace must be specified.
You may have noticed that the dot
. is used when specifying the view file in the example above
, which
means that the view file is located in
world.blade.php in the ``views/hello
directory of the plugin directory
. In other words, use a decimal point .
for directory hierarchy
positioning.
# pass data
The view is not just displaying the HTML you have written, you can pass some data from the plugin to the front-end page.
return view( 'Author\MyPlugin::hello.world' )->with( 'key' , $value ) ;
When you need to pass a lot of data, it is not elegant to use multiple
with methods, so you pass an associative array to the ``view
function:
return view( 'Author\MyPlugin::hello.world' , [ 'name' => 'Secret' , 'phone' => 2333 ]) ;
How are these data used? Read on.
# template inheritance
In order to keep the page of your plug-in basically consistent with the interface of the skin station, you should use template inheritance.
For a plugin, if you want to use the existing style of the skin station, your view file should look like this (Twig is used as an example):
{% extends 'parent page to be inherited' %}
{% block title %}page title{% endblock %}
{% block content %}
<!-- page content -->
{% endblock %}
The templates that can be inherited are generally user.base
or
admin.master
, which respectively represent the basic page of the user
center and the basic page of the management panel. Of course, you can
define another view yourself and inherit it (don’t forget to pay
attention to the namespace!) .