Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Adding constants info #147

Merged
merged 1 commit into from
May 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion docs/templating-guide/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,46 @@ tcp:
part: data
words:
- "{{a2}}"
```
```

### Constants
In addition to variables, you can also define constants in templates. Constants are similar to variables but have a distinct difference: their values cannot be overridden or changed, even by command-line variables. They are used to declare scalar values that remain fixed throughout the template. Constants are helpful when you want to ensure that a specific value remains unchanged across multiple template executions.

To declare a constant, use the `constants` keyword followed by the constant name and its value. Constants are declared at the template level, just like variables.

Example constants:

```yaml
constants:
p: test
```

In the above example, `p` is a constant with the values `test`

Here's an example template that uses constants:

```yaml
id: constants-example

info:
name: Constants Example
author: pdteam
severity: info

constants:
p: test

http:
- raw:
- |
GET /api/data?param={{p}} HTTP/1.1
Host: {{Hostname}}
matchers:
- type: word
words:
- "OK"
```

If the same variable is passed via CLI, the value remains `test` (`nuclei -V p=anothervalue ...`).

Constants provide a way to ensure that specific values remain constant and cannot be modified, providing consistency and predictability in your templates.