Views - Icybrew/Stackoverflow-documentation GitHub Wiki

Views

Views are structured HTML pages, that are used to render what end-user sees.
Every view uses twig as template engine and must be structured accordingly to twig standards.

Example

/* app/controllers/IndexController.php */
public function index() {
  // First parameter which view to load, second is optional data array
  $this->view('index', ['title' => 'My title', 'content' => 'Lorem ipsum ...']);
}


/* resources/views/index.php */
<html>
  <head>
  <title>{{ title }}</title>
  </head>
  <body>
    <p>{{ content }}</p>
  </body>
</htm>

Route function

To generate url to a given route, use {{ route('route.name', params) }} function.

Example

/* views/***.php.twig */

/* Without parameters */
<a href="{{ route('home') }}">Home</a>


/* With parameters */

/* config/routes.php */
Route::get('topic/{topic}', 'topicController@show')->name('topic.show');

<a href="{{ route('topic.show', {'topic': 1}) }}">Topic 1</a>

Method function

Method function is helper that generates hidden input field for additional PUT, PATCH, DELETE methods since forms cannot make those requests!

Example

/* views/***.php.twig */

<form action="" method="post">
{{ method('PUT') }}
...
</form>

Twig documentation

Twig designer documentation


⚠️ **GitHub.com Fallback** ⚠️