jetzig/demo/src/app/views/root.zig
Bob Farrell a78d53a19a Allow importing .zig files from src/ in views
Views are copied to zig-cache, meaning that any files in `src/` are not
available for `@import` by default. Copy all .zig files from `src/` into
zig-cache so that relative imports work as expected. This also removes
the need to specifically copy views into zig-cache as the full tree is
now present.

Also fix a bug in static route fallback - remove superfluous underscore
so static routes with non-matching params render default HTML/JSON
content.
2024-03-10 14:10:53 +00:00

19 lines
638 B
Zig

const jetzig = @import("jetzig");
const importedFunction = @import("../lib/example.zig").exampleFunction;
pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
var root = try data.object();
try root.put("message", data.string("Welcome to Jetzig!"));
try root.put("custom_number", data.integer(customFunction(100, 200, 300)));
try root.put("imported_number", data.integer(importedFunction(100, 200, 300)));
try request.response.headers.append("x-example-header", "example header value");
return request.render(.ok);
}
fn customFunction(a: i32, b: i32, c: i32) i32 {
return a + b + c;
}