|
| 1 | +<bx:try> |
| 2 | + <bx:script> |
| 3 | + // Global BIFs in embedded script - should be highlighted properly |
| 4 | + var config = DeserializeJSON(configData); |
| 5 | + var timestamp = Now(); |
| 6 | + var formattedTime = TimeFormat(timestamp, "HH:mm:ss"); |
| 7 | + var randomNum = RandRange(1, 100); |
| 8 | + |
| 9 | + WriteOutput("Config loaded at: " & formattedTime); |
| 10 | + WriteOutput("Random number: " & randomNum); |
| 11 | + |
| 12 | + // Array operations |
| 13 | + var items = ArrayNew(1); |
| 14 | + ArrayAppend(items, "Item 1"); |
| 15 | + ArrayAppend(items, "Item 2"); |
| 16 | + ArrayAppend(items, "Item 3"); |
| 17 | + |
| 18 | + var itemCount = ArrayLen(items); |
| 19 | + var lastItem = ArrayLast(items); |
| 20 | + |
| 21 | + // String operations |
| 22 | + var message = "Hello World"; |
| 23 | + var upperMessage = UCase(message); |
| 24 | + var messageLength = Len(message); |
| 25 | + var foundPos = Find("World", message); |
| 26 | + </bx:script> |
| 27 | + |
| 28 | + <bx:catch type="any" name="e"> |
| 29 | + <div class="error"> |
| 30 | + Error loading config: #e.message# |
| 31 | + </div> |
| 32 | + </bx:catch> |
| 33 | +</bx:try> |
| 34 | + |
| 35 | +<!-- Custom components - should be highlighted as entity.name.tag.boxlang --> |
| 36 | +<bx:userProfile userId="#users.id#" showDetails="true"> |
| 37 | + |
| 38 | +<bx:customWidget |
| 39 | + title="Dynamic Widget" |
| 40 | + data="#SerializeJSON(config)#" |
| 41 | + timestamp="#GetTickCount()#"> |
| 42 | +</bx:customWidget> |
| 43 | + |
| 44 | +<bx:output> |
| 45 | + <h1>BoxLang Template Demo</h1> |
| 46 | + |
| 47 | + <!-- Global Components - should be highlighted as support.class.component.boxlang --> |
| 48 | + <bx:query name="users" datasource="mydb"> |
| 49 | + SELECT id, name, email, created_date |
| 50 | + FROM users |
| 51 | + WHERE active = 1 |
| 52 | + ORDER BY name |
| 53 | + </bx:query> |
| 54 | + |
| 55 | + <bx:cache action="get" id="userCount" variable="cachedCount"> |
| 56 | + <bx:query name="countQuery" datasource="mydb"> |
| 57 | + SELECT COUNT(*) as total FROM users WHERE active = 1 |
| 58 | + </bx:query> |
| 59 | + <bx:cache action="put" id="userCount" value="#countQuery.total#"> |
| 60 | + </bx:cache> |
| 61 | + |
| 62 | + <h2>User List (#cachedCount# total users)</h2> |
| 63 | + |
| 64 | + <bx:loop query="users"> |
| 65 | + <div class="user-card"> |
| 66 | + <h3>#users.name#</h3> |
| 67 | + <p>Email: #users.email#</p> |
| 68 | + |
| 69 | + <!-- Using global BIFs in template context --> |
| 70 | + <p>Member since: #DateFormat(users.created_date, 'mmmm d, yyyy')#</p> |
| 71 | + <p>Name length: #Len(users.name)# characters</p> |
| 72 | + <p>Uppercase name: #UCase(users.name)#</p> |
| 73 | + |
| 74 | + <bx:if condition="Find('g', users.email) GT 0"> |
| 75 | + <span class="verified">✓ Valid email format</span> |
| 76 | + </bx:if> |
| 77 | + </div> |
| 78 | + </bx:loop> |
| 79 | + |
| 80 | + <!-- HTTP component for API calls --> |
| 81 | + <bx:http url="https://api.example.com/stats" method="GET" result="apiResponse"> |
| 82 | + <bx:httpparam type="header" name="Authorization" value="Bearer #session.token#"> |
| 83 | + <bx:httpparam type="header" name="Content-Type" value="application/json"> |
| 84 | + </bx:http> |
| 85 | + |
| 86 | + <bx:if condition="apiResponse.statusCode EQ '200 OK'"> |
| 87 | + <div class="api-stats"> |
| 88 | + <h3>API Statistics</h3> |
| 89 | + <pre>#HTMLCodeFormat(apiResponse.fileContent)#</pre> |
| 90 | + </div> |
| 91 | + </bx:if> |
| 92 | + |
| 93 | + <!-- File operations --> |
| 94 | + <bx:file action="read" file="#ExpandPath('./data/config.json')#" variable="configFile"> |
| 95 | + |
| 96 | + <bx:try> |
| 97 | + <bx:script> |
| 98 | + var parsedConfig = DeserializeJSON(configFile); |
| 99 | + var appName = parsedConfig.application.name; |
| 100 | + var version = parsedConfig.application.version; |
| 101 | + </bx:script> |
| 102 | + |
| 103 | + <div class="config-info"> |
| 104 | + <h3>Application: #appName# v#version#</h3> |
| 105 | + </div> |
| 106 | + |
| 107 | + <bx:catch type="any" name="configError"> |
| 108 | + <div class="error"> |
| 109 | + Error parsing config: #configError.message# |
| 110 | + </div> |
| 111 | + </bx:catch> |
| 112 | + </bx:try> |
| 113 | + |
| 114 | + <!-- More custom components --> |
| 115 | + <bx:navigation items="#navigationItems#" activeItem="#currentPage#"> |
| 116 | + |
| 117 | + <bx:sidebar> |
| 118 | + <bx:widget type="calendar" data="#calendarData#"> |
| 119 | + <bx:widget type="recent-posts" count="5"> |
| 120 | + <bx:widget type="user-stats" userId="#session.userId#"> |
| 121 | + </bx:sidebar> |
| 122 | + |
| 123 | + <bx:footer> |
| 124 | + <bx:set name="currentYear" value="#Year(Now())#"> |
| 125 | + <p>© #currentYear# My Application. All rights reserved.</p> |
| 126 | + </bx:footer> |
| 127 | +</bx:output> |
0 commit comments