From 46f0b5038c76c10b547873104a5d92b3e9c75aca Mon Sep 17 00:00:00 2001 From: Samuel Webb Date: Sun, 7 Apr 2024 16:29:33 -0400 Subject: [PATCH] Update to ZMPL v2 --- src/app/views/root.zig | 7 +++---- src/app/views/root/_content.zmpl | 5 +++-- src/app/views/root/index.zmpl | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/views/root.zig b/src/app/views/root.zig index 0fa146c..d567fc5 100644 --- a/src/app/views/root.zig +++ b/src/app/views/root.zig @@ -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. diff --git a/src/app/views/root/_content.zmpl b/src/app/views/root/_content.zmpl index 088ab6b..89ce5ae 100644 --- a/src/app/views/root/_content.zmpl +++ b/src/app/views/root/_content.zmpl @@ -1,5 +1,6 @@ -

{.message}

+@args message: *ZmplValue +

{{message}}

@@ -15,6 +16,6 @@
Search for an artist, album, or song: - +
diff --git a/src/app/views/root/index.zmpl b/src/app/views/root/index.zmpl index 9473e7a..38e3ef7 100644 --- a/src/app/views/root/index.zmpl +++ b/src/app/views/root/index.zmpl @@ -11,11 +11,11 @@
-

{.message_param}

+

{{.message_param}}

- @partial root/content + @partial root/content(message: .welcome_message)