MuntasirSZN | 14da0fb | 2025-03-09 08:49:14 +0100 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="UTF-8"> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | <title>{{ page_title | default(value="Tera Test") }}</title> |
| 7 | {% if include_styles %} |
| 8 | <style> |
| 9 | body { |
| 10 | font-family: {{ font_family | default(value="sans-serif") }}; |
| 11 | color: #333; |
| 12 | line-height: 1.6; |
| 13 | } |
| 14 | .container { |
| 15 | width: 80%; |
| 16 | margin: 0 auto; |
| 17 | } |
| 18 | {% if dark_mode %} |
| 19 | body { |
| 20 | background-color: #222; |
| 21 | color: #eee; |
| 22 | } |
| 23 | {% endif %} |
| 24 | </style> |
| 25 | {% endif %} |
| 26 | </head> |
| 27 | <body> |
| 28 | <div class="container"> |
| 29 | {# Header Section with variable interpolation #} |
| 30 | <header> |
| 31 | <h1>{{ header_text | upper }}</h1> |
| 32 | {% if subheader %} |
| 33 | <h2>{{ subheader }}</h2> |
| 34 | {% endif %} |
| 35 | </header> |
| 36 | |
| 37 | {# Navigation example with for loop #} |
| 38 | <nav> |
| 39 | <ul> |
| 40 | {% for item in navigation %} |
| 41 | <li class="{{ loop.index0 == current_page ? 'active' : '' }}"> |
| 42 | <a href="{{ item.url }}">{{ item.title }}</a> |
| 43 | </li> |
| 44 | {% endfor %} |
| 45 | </ul> |
| 46 | </nav> |
| 47 | |
| 48 | {# Main content section with various template features #} |
| 49 | <main> |
| 50 | {# Conditionals #} |
| 51 | {% if user %} |
| 52 | <section class="welcome"> |
| 53 | <h2>Welcome back, {{ user.name }}!</h2> |
| 54 | <p>Last login: {{ user.last_login | date(format="%Y-%m-%d") }}</p> |
| 55 | </section> |
| 56 | {% elif visitor_count > 0 %} |
| 57 | <section class="welcome"> |
| 58 | <h2>Welcome, visitor!</h2> |
| 59 | <p>You are visitor number {{ visitor_count }}</p> |
| 60 | </section> |
| 61 | {% else %} |
| 62 | <section class="welcome"> |
| 63 | <h2>Welcome to our site!</h2> |
| 64 | </section> |
| 65 | {% endif %} |
| 66 | |
| 67 | {# Macro definition and usage #} |
| 68 | {% macro render_item(item, featured=false) %} |
| 69 | <div class="item {{ featured ? 'featured' : '' }}"> |
| 70 | <h3>{{ item.title }}</h3> |
| 71 | <p>{{ item.description | truncate(length=100) }}</p> |
| 72 | {% if item.tags %} |
| 73 | <div class="tags"> |
| 74 | {% for tag in item.tags %} |
| 75 | <span class="tag">{{ tag }}</span> |
| 76 | {% endfor %} |
| 77 | </div> |
| 78 | {% endif %} |
| 79 | </div> |
| 80 | {% endmacro render_item %} |
| 81 | |
| 82 | {# Items section with macro usage #} |
| 83 | <section class="items"> |
| 84 | <h2>Items ({{ items | length }})</h2> |
| 85 | |
| 86 | {% for item in items %} |
| 87 | {{ self::render_item(item=item, featured=item.id == featured_id) }} |
| 88 | |
| 89 | {% if not loop.last %} |
| 90 | <hr> |
| 91 | {% endif %} |
| 92 | {% endfor %} |
| 93 | </section> |
| 94 | |
| 95 | {# Raw content that shouldn't be processed #} |
| 96 | {% raw %} |
| 97 | <div class="example"> |
| 98 | The syntax {{ variable }} will not be processed in raw blocks. |
| 99 | Neither will {% control %} structures. |
| 100 | </div> |
| 101 | {% endraw %} |
| 102 | |
| 103 | {# Includes #} |
| 104 | {% include "partials/footer.tera" %} |
| 105 | |
| 106 | {# Inheritance example #} |
| 107 | {% block content %} |
| 108 | <p>This is the default content.</p> |
| 109 | {% endblock content %} |
| 110 | |
| 111 | {# Set variables #} |
| 112 | {% set text_color = dark_mode ? "#fff" : "#333" %} |
| 113 | {% set items_count = items | length %} |
| 114 | |
| 115 | <div style="color: {{ text_color }}"> |
| 116 | We have {{ items_count }} items. |
| 117 | </div> |
| 118 | |
| 119 | {# Filters with complex expressions #} |
| 120 | <p>{{ "Hello, " ~ user.name | default(value="Guest") | upper }}</p> |
| 121 | <p>{{ items | filter(attribute="featured", value=true) | length }} featured items</p> |
| 122 | |
| 123 | {# With statement #} |
| 124 | {% with %} |
| 125 | {% set local_var = "Only visible in this scope" %} |
| 126 | <p>{{ local_var }}</p> |
| 127 | {% endwith %} |
| 128 | |
| 129 | {# Mathematical operations #} |
| 130 | <div class="math"> |
| 131 | <p>Price: ${{ price }}</p> |
| 132 | <p>Tax ({{ tax_rate * 100 }}%): ${{ price * tax_rate }}</p> |
| 133 | <p>Total: ${{ price * (1 + tax_rate) }}</p> |
| 134 | </div> |
| 135 | |
| 136 | {# Boolean operations #} |
| 137 | {% if user and user.is_admin or super_user %} |
| 138 | <div class="admin-panel">Admin panel</div> |
| 139 | {% endif %} |
| 140 | </main> |
| 141 | |
| 142 | {# Footer section with filters and includes #} |
| 143 | <footer> |
| 144 | <p>© {{ current_year }} {{ company_name | default(value="Our Company") }}</p> |
| 145 | |
| 146 | {% if debug %} |
| 147 | <div class="debug-info"> |
| 148 | <p>Render time: {{ render_time }}ms</p> |
| 149 | <p>Template version: {{ version }}</p> |
| 150 | </div> |
| 151 | {% endif %} |
| 152 | </footer> |
| 153 | </div> |
| 154 | |
| 155 | <script> |
| 156 | const appData = { |
| 157 | "user": {% if user %}{{ user | json_encode() }}{% else %}null{% endif %}, |
| 158 | "settings": { |
| 159 | "theme": "{{ theme | default(value="light") }}", |
| 160 | "notifications": {{ notifications_enabled | string | lower }} |
| 161 | } |
| 162 | }; |
| 163 | </script> |
| 164 | </body> |
| 165 | </html> |