aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/template-demo/main.c4
-rw-r--r--examples/template-demo/templates/index.html49
2 files changed, 53 insertions, 0 deletions
diff --git a/examples/template-demo/main.c b/examples/template-demo/main.c
index 2adbb52..9989a68 100644
--- a/examples/template-demo/main.c
+++ b/examples/template-demo/main.c
@@ -26,6 +26,10 @@ int templating_handler(UrlParams *params) {
context_set(&ctx, "safe_html", "This is <b>bold</b> and <i>italic</i> HTML.");
context_set(&ctx, "unsafe_html", "<script>alert(0);");
+ context_set(&ctx, "user_logged_in", "true");
+ context_set(&ctx, "role", "admin");
+ context_set(&ctx, "status", "active");
+
char *features[] = {"Fast and Lightweight", "Simple API",
"Basic Routing", "Templating Engine",
"Static File Serving", "Cookie Management"};
diff --git a/examples/template-demo/templates/index.html b/examples/template-demo/templates/index.html
index 837688f..2a08485 100644
--- a/examples/template-demo/templates/index.html
+++ b/examples/template-demo/templates/index.html
@@ -40,6 +40,55 @@
{{endfor}}
</ul>
+ <h2>Conditional Statements (if/elif/else)</h2>
+
+ <h3>Simple truthy check</h3>
+ <p>
+ {{if user_logged_in}}
+ <span class="highlight">User is logged in!</span>
+ {{else}}
+ <span>User is NOT logged in.</span>
+ {{endif}}
+ </p>
+
+ <h3>Equality check (role == "admin")</h3>
+ <p>
+ {{if role == "admin"}}
+ <span class="highlight">Welcome, Admin! You have full access.</span>
+ {{elif role == "user"}}
+ <span>Welcome, User! You have standard access.</span>
+ {{else}}
+ <span>Welcome, Guest! You have limited access.</span>
+ {{endif}}
+ </p>
+
+ <h3>Not equal check (status != "inactive")</h3>
+ <p>
+ {{if status != "inactive"}}
+ <span class="highlight">Account is active.</span>
+ {{else}}
+ <span>Account is inactive.</span>
+ {{endif}}
+ </p>
+
+ <h3>Variable existence check (exists)</h3>
+ <p>
+ {{if exists username}}
+ <span class="highlight">Username exists!</span>
+ {{else}}
+ <span>Username does NOT exist.</span>
+ {{endif}}
+ </p>
+
+ <h3>Variable existence check (not exists)</h3>
+ <p>
+ {{if not exists missing_var}}
+ <span class="highlight">missing_var does NOT exist (as expected)</span>
+ {{else}}
+ <span>missing_var exists (unexpected!)</span>
+ {{endif}}
+ </p>
+
<div class="footer">
<p>Rendered at: {{timestamp}}</p>
</div>