Repository navigation
Views
Laravex renders views with a Blade-compatible template engine. View files live in resources/views/ and are located by name using dot notation. The .blade.php extension is preferred; .html and .eex are also supported as fallbacks.
Place template files in resources/views/:
resources/views/
welcome.blade.php
posts/
index.blade.php
show.blade.php
layouts/
app.blade.php
components/
alert.blade.php
Call Laravex.View.make/2 from a route handler or controller. It returns a Laravex.Http.Response with Content-Type: text/html:
alias Laravex.View
def index(_request) do
posts = App.Models.Post.all()
View.make("posts.index", %{posts: posts})
end
def show(request) do
post = request.params["post"]
View.make("posts.show", %{post: post, title: post["title"]})
endThe view/2 helper (available via use App.Http.Controllers.Controller) is an alias for View.make/2:
view("posts.index", %{posts: posts})Pass any Elixir map as the second argument. Keys are stringified, so both atom and string keys work in templates:
View.make("dashboard", %{
user: current_user,
stats: %{posts: 12, comments: 44},
recent: recent_posts
})Access data in templates with {{ $key }} or {{ key }} (the $ prefix is optional).
Errors, old input, flash messages, and the CSRF token are merged into every view automatically by the ShareErrors and ShareFlash middleware and View.merge_shared/1:
| Key | Description |
|---|---|
errors |
Validation error map from the previous request |
old |
Input values from the previous request |
flash |
Flash messages aged for this request |
_token / csrf_token
|
CSRF token from the session |
You do not need to pass these manually.
View.make/2 searches for the view file in this order:
resources/views/{name}.blade.phpresources/views/components/{name}.blade.phpresources/views/{name}.htmlresources/views/{name}.eex
Dot notation maps to directory separators: "posts.show" → resources/views/posts/show.blade.php.
Rendered content is cached at the file level by Laravex.View.Cache. The cache is automatically invalidated when the source file changes.
For programmatic rendering without a file, use View.render_string/2:
html = Laravex.View.render_string("<h1>{{ title }}</h1>", %{"title" => "Hello"})This passes through the full Blade compiler pipeline. See Blade-Templates for the complete directive reference.
Laravex — Laravel-faithful application skeleton & runtime for Elixir.
GitHub
·
Docs
·
Limitations
·
Laravel Docs
Not affiliated with Laravel LLC or the Elixir core team. Built to feel like Laravel on the BEAM.
- Home
- Installation
- Configuration
- Directory-Structure
- Request-Lifecycle
- Service-Container
- Service-Providers
- Deployment
- Routing
- Middleware
- CSRF-Protection
- Controllers
- Requests
- Responses
- Views
- Blade-Templates
- Asset-Bundling
- Session
- Validation
- Error-Handling
- Logging
- Artisan-Console
- Broadcasting
- Cache
- Collections
- Events
- File-Storage
- Helpers
- HTTP-Client
- Localization
- Notifications
- Pipeline
- Queues
- Rate-Limiting
- Strings
- Task-Scheduling