|
| 1 | +# URL Query Value |
| 2 | + |
| 3 | +Use `url-query-value` inline plugin to display a value from URL query parameter. |
| 4 | +This can be useful for onboarding pages or runbooks where commands or settings change based on user or some runtime |
| 5 | +information, and you can generate a link, providing additional information. |
| 6 | + |
| 7 | +# Inline Syntax |
| 8 | + |
| 9 | + `:url-query-value: officeName {default: "NYC-15"}` |
| 10 | + |
| 11 | +Renders as: `:url-query-value: officeName {default: "NYC-15"}` |
| 12 | + |
| 13 | +The `officeName` is the query parameter name to read from the URL. |
| 14 | + |
| 15 | +Click [SF office](layout/runtime-templates?officeName=SF) to see the value above change. |
| 16 | + |
| 17 | +# Missing Value |
| 18 | + |
| 19 | +When no `default` is specified and the query parameter is not present, an error is displayed: |
| 20 | + |
| 21 | + `:url-query-value: clusterName` |
| 22 | + |
| 23 | +Renders as: `:url-query-value: clusterName` |
| 24 | + |
| 25 | +# Template Syntax In Code Snippets And CLI Commands |
| 26 | + |
| 27 | +Use `${paramName}` or `${paramName:defaultValue}` syntax inside code snippets to substitute values from URL query parameters. |
| 28 | +Enable it by setting `templateUseQueryParam: true` on the code block. |
| 29 | + |
| 30 | + ```shell {templateUseQueryParam: true} |
| 31 | + ssh ${userName:admin}@server-${officeName:NYC}.example.com |
| 32 | + ``` |
| 33 | + |
| 34 | +```shell {templateUseQueryParam: true} |
| 35 | +ssh ${userName:admin}@server-${officeName:NYC}.example.com |
| 36 | +``` |
| 37 | + |
| 38 | + ```cli {templateUseQueryParam: true} |
| 39 | + kubectl config use-context ${officeName:NYC}-cluster |
| 40 | + ``` |
| 41 | + |
| 42 | +```cli {templateUseQueryParam: true} |
| 43 | +kubectl config use-context ${officeName:NYC}-cluster |
| 44 | +``` |
| 45 | + |
| 46 | +Without query parameters, default values are used. When the page URL contains `?userName=jdoe&officeName=SF`, the substituted values will appear. |
| 47 | + |
| 48 | +Without default values, you get error message when no query parameter is supplied: |
| 49 | + |
| 50 | + ```cli {templateUseQueryParam: true} |
| 51 | + kubectl config use-context ${myQueryParam}-cluster |
| 52 | + ``` |
| 53 | + |
| 54 | +```cli {templateUseQueryParam: true} |
| 55 | +kubectl config use-context ${myQueryParam}-cluster |
| 56 | +``` |
| 57 | + |
| 58 | +# Tables With Inline Values |
| 59 | + |
| 60 | +You can use inline `url-query-value` anywhere were text is expected, for example in table cells: |
| 61 | + |
| 62 | +```markdown |
| 63 | + |
| 64 | +| Setting | Value | |
| 65 | +|---------------|-----------------------------------------------------------------| |
| 66 | +| Office | `:url-query-value: officeName {default: "NYC"}` | |
| 67 | +| Floor | `:url-query-value: floorNumber {default: "5"}` | |
| 68 | +| Wi-Fi Network | `:url-query-value: officeName {default: "NYC"}`-internal | |
| 69 | +| VPN Server | vpn-`:url-query-value: officeName {default: "NYC"}`.example.com | |
| 70 | +``` |
| 71 | +| Setting | Value | |
| 72 | +|---------------|-----------------------------------------------------------------| |
| 73 | +| Office | `:url-query-value: officeName {default: "NYC"}` | |
| 74 | +| Floor | `:url-query-value: floorNumber {default: "5"}` | |
| 75 | +| Wi-Fi Network | `:url-query-value: officeName {default: "NYC"}`-internal | |
| 76 | +| VPN Server | vpn-`:url-query-value: officeName {default: "NYC"}`.example.com | |
| 77 | + |
| 78 | +# Full Example |
| 79 | + |
| 80 | +Click one of the links below to see how values on this page change: |
| 81 | + |
| 82 | +* [SF office, floor 3](layout/runtime-templates?officeName=SF&floorNumber=3&userName=jdoe) |
| 83 | +* [NYC office, floor 12](layout/runtime-templates?officeName=NYC&floorNumber=12&userName=admin) |
| 84 | +* [London office, floor 7](layout/runtime-templates?officeName=London&floorNumber=7&userName=alice) |
| 85 | +* [Default values](layout/runtime-templates) |
| 86 | + |
| 87 | +## Setup Instructions |
| 88 | + |
| 89 | +Welcome to the `:url-query-value: officeName {default: "NYC"}` office! |
| 90 | + |
| 91 | +Connect to the office VPN: |
| 92 | + |
| 93 | +```cli {templateUseQueryParam: true} |
| 94 | +sudo vpn connect ${officeName:NYC}-gateway.example.com --user ${userName:admin} |
| 95 | +``` |
| 96 | + |
| 97 | +Configure your local environment: |
| 98 | + |
| 99 | +```shell {templateUseQueryParam: true} |
| 100 | +export OFFICE=${officeName:NYC} |
| 101 | +export FLOOR=${floorNumber:5} |
| 102 | +export PRINTER=printer-${officeName:NYC}-${floorNumber:5} |
| 103 | +``` |
| 104 | + |
| 105 | +Print a test page: |
| 106 | + |
| 107 | +```cli {templateUseQueryParam: true} |
| 108 | +lp -d printer-${officeName:NYC}-${floorNumber:5} /etc/motd |
| 109 | +``` |
| 110 | + |
| 111 | +Note: If you have a predetermined set of values, consider using [Page Tabs](layout/page-tabs) or [Tabs](layout/tabs) instead |
0 commit comments