This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
/
string-template.html
197 lines (157 loc) · 9.36 KB
/
string-template.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta property="og:url" content="https://ballerinalang.org" />
<meta property="og:type" content="article" />
<meta property="og:title" content="Flexible. Powerful. Beautiful." />
<meta property="og:description" content="Ballerina by Example is a hands-on introduction to Ballerina using annotated example programs. Check out the first example or browse the full list below. " />
<meta property="og:image" content="http://ballerinalang.org/img/ballerina-fb.jpg" />
<link rel="shortcut icon" href="https://ballerinalang.org/img/favicon.ico" type="image/x-icon">
<link rel="icon" href="https://ballerinalang.org/img/favicon.ico" type="image/x-icon">
<title>Ballerina by Example: String Template</title>
<!--GA-->
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-92163714-1', 'auto');
ga('send', 'pageview');
</script>
<!-- Google Tag Manager -->
<script>(function (w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({'gtm.start':
new Date().getTime(), event: 'gtm.js'});
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src =
'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-KW2LLTW');
</script>
<!-- End Google Tag Manager -->
<!-- Hotjar Tracking Code for https://ballerinalang.org/ -->
<script>
(function (h, o, t, j, a, r) {
h.hj = h.hj || function () {
(h.hj.q = h.hj.q || []).push(arguments)
};
h._hjSettings = {hjid: 442732, hjsv: 5};
a = o.getElementsByTagName('head')[0];
r = o.createElement('script');
r.async = 1;
r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
a.appendChild(r);
})(window, document, '//static.hotjar.com/c/hotjar-', '.js?sv=');
</script>
<link href="https://b.content.wso2.com/sites/all/bootstrap/css/bootstrap.css?230617" rel="stylesheet">
<script src="https://b.content.wso2.com/sites/all/bootstrap/js/jquery.js?230617"></script>
<script src="https://b.content.wso2.com/sites/all/bootstrap/js/bootstrap.js?230617"></script>
<script src="https://b.content.wso2.com/sites/all/ballerina/ballerina-example.js"></script>
<script defer="defer" src="https://wso2.cachefly.net/wso2/sites/all/ballerina/js/ballerina.js"></script>
<link rel=stylesheet href="site.css">
<link href="https://fonts.googleapis.com/css?family=Cairo:200,300,400,600,700,900" rel="stylesheet">
<link rel=stylesheet href="https://b.content.wso2.com/sites/all/ballerina/ballerina-example.css">
</head>
<body>
<div class="row cBallerinaNav" id="iBallerinaNavigation">
</div>
<div class="row cBallerinaBySampleRow">
<div class="container cBallerinaBySampleContainer">
<div class="FullCode">
<div class="highlight"><pre><span class="kd">function</span> <span class="nx">main</span> <span class="p">(</span><span class="kt">string</span><span class="p">[]</span> <span class="nx">args</span><span class="p">)</span> <span class="p">{</span> <span class="kt">string</span> <span class="nx">name</span> <span class="p">=</span> <span class="s">"Ballerina"</span><span class="p">;</span>
<span class="kt">string</span> <span class="nx">template</span> <span class="p">=</span> <span class="kt">string</span> <span class="s">`Hello {{name}}!!!`</span><span class="p">;</span>
<span class="nb">println</span><span class="p">(</span><span class="nx">template</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
<div class="example" id="string-template">
<div class="col-xs-11 col-sm-11 col-md-11">
<h2><a href="./">Ballerina by Example</a>: String Template</h2>
</div>
<div class="col-xs-1 col-sm-1 col-md-1">
<a href="./" class="cBackButton"><img src="http://b.content.wso2.com/sites/all/ballerina/backbutton.svg"/></a>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<table>
<tr>
<td class="docs">
<p>String templates allow you to embed expressions in strings. You
can add any expression inside {{}} as long as the expression
produces a string type output after evaluating.</p>
</td>
<td class="code leading">
<div class="highlight"><pre><span class="kd">function</span> <span class="nx">main</span> <span class="p">(</span><span class="kt">string</span><span class="p">[]</span> <span class="nx">args</span><span class="p">)</span> <span class="p">{</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
</td>
<td class="code leading">
<div class="highlight"><pre> <span class="kt">string</span> <span class="nx">name</span> <span class="p">=</span> <span class="s">"Ballerina"</span><span class="p">;</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<p>Create a string template.</p>
</td>
<td class="code leading">
<div class="highlight"><pre> <span class="kt">string</span> <span class="nx">template</span> <span class="p">=</span> <span class="kt">string</span> <span class="s">`Hello {{name}}!!!`</span><span class="p">;</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<p>Lets print the final string value of the template.</p>
</td>
<td class="code">
<div class="highlight"><pre> <span class="nb">println</span><span class="p">(</span><span class="nx">template</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td>
</tr>
</table>
<table>
<tr>
<td class="docs">
<p>To run the program, put the code in “string-template.bal”
and use “ballerina run” command.</p>
</td>
<td class="code">
<div class="highlight"><pre><span class="gp">$</span> ballerina run string-template.bal
<span class="go">Hello Ballerina!!!</span>
</pre></div>
</td>
</tr>
</table>
<p class="next">
Next example: <a href="inbound-request-with-multiparts">Inbound Request with Multiparts</a>.
</p>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 cGOfooter">
<p class="footer">
by <a href="https://twitter.com/ballerinalang">@ballerinalang</a> | <a href="mailto:ballerina-dev@googlegroups.com">feedback</a> | <a href="https://github.com/ballerinalang/ballerina/tree/master/samples/ballerina-by-example/examples/string-template">source</a>
</p>
<p class="attrib">
This site was generated using a <a href="https://github.com/mmcgrana/gobyexample/">tool</a> developed by <a href="https://twitter.com/mmcgrana">@mmcgrana</a>, licensed under <a href="https://creativecommons.org/licenses/by/2.0/">CC BY</a> / modified from original
</p>
</div>
</div>
</div>
</div>
<div class="row cBallerinaFooter" id="iBallerinaFooter">
</div>
</body>
</html>