# Template Functions

Template functions are already predefined functions that can be used to ease the use of tokens. These functions can be used in places where you are allowed to use tokens, like email, push notification templates.

{% hint style="warning" %}
These functions **cannot** be used in collection aggregates even though you are allowed to use tokens there.
{% endhint %}

## Functions

The following shows all of the available functions.

### Date Time functions

These functions help to work with dates, such as converting milliseconds to date string and other.

```csharp
// Takes in milliseconds as a number or string and a format.
// Returns formatted date string
string UnixTimeToDateString(long? ms, string format = "yyyy-MM-dd") {...}
string UnixTimeToDateString(string ms, string format = "yyyy-MM-dd") {...}
```

### Other functions

```csharp
// Safe way to get a property
// Returns a property by name, or null if not found
dynamic GetProperty(dynamic obj, string name) {...}
```

## Usage Example

The following shows how to use these functions. Example is taken from email template.

```csharp
<h1>Welcome to project @Model.Project.Name.</h1>

<p>Current date: @UnixTimeToDateString(@Model.DateMillis, "dd/MM/yyyy")</p>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.codemash.io/other-topics/tokens-binding/template-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
