KScript docs
EN

Routes and APIs

Views

@view('people/show', person: $p) renders views/people/show.html (or .md). If that file doesn't exist, it renders people/show.html in the site folder. You may leave off the extension. The named values become the view's variables, and $request is there too. Views are ordinary pages, so layouts, components, <include> and <live> all work in them.

The views folder is never served as pages, because a view needs its controller's data.

The editor reads every @view('people/show', ...) in the project's scripts, so it knows what each view is given. In views/people/show.html, typing $ offers $person, $person. offers the fields the controller gave it, and a loop over a list it was given knows the fields of each item. Hovering $person says which controller passes it, and Go to Definition opens that call. A view that names a package with <import package="KScript.Auth" /> gets that package's variables too, so $session-> lists the session's methods.

Edit this page on GitHub