URL parameters (also known as query strings) pass information to your web application through the URL. If you've ever seen a really long URL with `?id=`, you've seen URL parameters in action.
The syntax for URL parameters always starts with a question mark ( `?` ), followed by key-value pairs separated by an equal sign ( `=` ). Separate multiple parameters with the ampersand ( `&` ).
A simple case would be
```
https://www.my-app.com?id=1
```
Here the URL parameter name is `id` and its value is `1`.
Parse the parameter values in [[base/Google Apps Script/Google Apps Script]] within the `doGet` function using the `parameter` method on the event object `e`.
Here we are checking first for the parameter named `id`, if it is present we execute some code and if not we execute a different code block.
```javascript
function doGet(e) {
if(e.parameter.id){
// code here
} else {
// code here
}
}
```
To affect the content or layout of the web app, you will combine URL parameters with printing [[scriptlets]]. Printing scriptlets output the result of their code to the screen.
This example will simply print the parameter value to the screen. First create an HTML file and add a paragraph ( `<p>` ) tag. Inside the paragraph create a template string named text with `<?= text ?>`.
```HTML
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p><?= text ?></p>
</body>
</html>
```
In `Code.gs`, create a `doGet` function that reads the `text` parameter from the event object and, if present, passes it to the HTML template. If not present, print a warning statement instead. (The name of the parameter and name of the scriptlet variable do not need to be the same).
```javascript
function doGet(e) {
if(e.parameter.text){
let template = HtmlService.createTemplateFromFile('index');
template.text = e.parameter.text;
return template.evaluate();
} else {
let template = HtmlService.createTemplateFromFile('index');
template.text = "No 'text' parameter found!"
return template.evaluate();
}
}
```
For template strings to function properly, we use the `createTemplateFromFile` method and `evaluate` the template after updating the template string. See [[Templated HTML]] for more details.
You can now deploy the app and append any text to the URL and see it printed to the screen. For example,
```
https://script.google.com/macros/s/<app-id>/exec?text=hello%20world
```
will print "hello world". Note that for URLs spaces are coded as `%20`.