Update Jetzig

This commit is contained in:
Samuel Webb 2024-09-13 13:44:38 -04:00
parent fa4c3a6eff
commit b1a21d63df
4 changed files with 47 additions and 4 deletions

41
src/app/views/music.zig Normal file
View file

@ -0,0 +1,41 @@
const std = @import("std");
const jetzig = @import("jetzig");
pub const static_params = .{
.index = .{
//.{ .params = .{ .foo = "hi", .bar = "bye" } },
//.{ .params = .{ .foo = "hello", .bar = "goodbye" } },
},
//.get = .{
// .{ .id = "1", .params = .{ .foo = "hi", .bar = "bye" } },
// .{ .id = "2", .params = .{ .foo = "hello", .bar = "goodbye" } },
//},
};
pub fn index(request: *jetzig.StaticRequest, data: *jetzig.Data) !jetzig.View {
var root = try data.object();
const params = try request.params();
if (params.get("foo")) |foo| try root.put("foo", foo);
if (params.get("foo") == null) try root.put("foo", data.string("no foo"));
if (params.get("bar")) |bar| try root.put("bar", bar);
if (params.get("bar") == null) try root.put("bar", data.string("no bar"));
return request.render(.ok);
}
//pub fn get(id: []const u8, request: *jetzig.StaticRequest, data: *jetzig.Data) !jetzig.View {
// var root = try data.object();
//
// const params = try request.params();
//
// if (std.mem.eql(u8, id, "1")) {
// try root.put("id", data.string("id is '1'"));
// }
//
// if (params.get("foo")) |foo| try root.put("foo", foo);
// if (params.get("bar")) |bar| try root.put("bar", bar);
//
// return request.render(.created);
//}

View file

@ -0,0 +1,2 @@
<div>{{.foo}}</div>
<div>{{.bar}}</div>