diff options
| author | frosty <gabriel@bwaaa.monster> | 2026-03-12 18:13:04 -0400 |
|---|---|---|
| committer | frosty <gabriel@bwaaa.monster> | 2026-03-12 18:13:04 -0400 |
| commit | 4722542caf4192fe702adc975e8ee557e3526426 (patch) | |
| tree | a9419dea2815652f3f53ab8d90009774494883fc /examples | |
| parent | ec82c9ec4eb40ba28c228414e501d73ecc5326af (diff) | |
| download | beaker-4722542caf4192fe702adc975e8ee557e3526426.tar.gz | |
feature: added conditionals + added examples
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/template-demo/main.c | 4 | ||||
| -rw-r--r-- | examples/template-demo/templates/index.html | 49 |
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> |
