Update to ZMPL v2
This commit is contained in:
parent
199dc0ca49
commit
46f0b5038c
3 changed files with 8 additions and 8 deletions
|
|
@ -1,3 +1,4 @@
|
|||
const std = @import("std");
|
||||
const jetzig = @import("jetzig");
|
||||
|
||||
/// `src/app/views/root.zig` represents the root URL `/`
|
||||
|
|
@ -18,7 +19,7 @@ pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
|
|||
var root = try data.object();
|
||||
|
||||
// Add a string to the root object.
|
||||
try root.put("message", data.string("Welcome to Jetzig!"));
|
||||
try root.put("welcome_message", data.string("Welcome to Jetzig!"));
|
||||
|
||||
// Request params have the same type as a `data.object()` so they can be inserted them
|
||||
// directly into the response data. Fetch `http://localhost:8080/?message=hello` to set the
|
||||
|
|
@ -26,9 +27,7 @@ pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
|
|||
// present.
|
||||
const params = try request.params();
|
||||
|
||||
if (params.get("message")) |value| {
|
||||
try root.put("message_param", value);
|
||||
}
|
||||
try root.put("message_param", params.get("message"));
|
||||
|
||||
// Set arbitrary response headers as required. `content-type` is automatically assigned for
|
||||
// HTML, JSON responses.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<!--// Renders the `message` response data value.-->
|
||||
<h3 class="message text-[#39b54a]">{.message}</h3>
|
||||
@args message: *ZmplValue
|
||||
<h3 class="message text-[#39b54a]">{{message}}</h3>
|
||||
|
||||
<div><img class="p-3 mx-auto" src="/jetzig.png" /></div>
|
||||
|
||||
|
|
@ -15,6 +16,6 @@
|
|||
<div>
|
||||
<a class="font-bold text-[#39b54a]">Search for an artist, album, or song:</a>
|
||||
<input type="text" name="search" hx-include="[name='search']" hx-get="/test" hx-trigger="keyup[keyCode==13]">
|
||||
<button type="button" hx-include="[name='search']" hx-get="/test">You whattup</button>
|
||||
<button type="button" hx-include="[name='search']" hx-get="/test">Yo whattup</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@
|
|||
<div class="text-center pt-10 m-auto">
|
||||
<!-- If present, renders the `message_param` response data value, add `?message=hello` to the
|
||||
// URL to see the output: -->
|
||||
<h2 class="param text-3xl text-[#f7931e]">{.message_param}</h2>
|
||||
<h2 class="param text-3xl text-[#f7931e]">{{.message_param}}</h2>
|
||||
|
||||
<!--// Renders `src/app/views/root/_content.zmpl` with the same template data available:-->
|
||||
<div>
|
||||
@partial root/content
|
||||
@partial root/content(message: .welcome_message)
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue