An open API service indexing awesome lists of open source software.

https://github.com/nagilum/tempy

C# Template Engine
https://github.com/nagilum/tempy

Last synced: 3 months ago
JSON representation

C# Template Engine

Awesome Lists containing this project

README

        

# Tempy

## Layout

### Settings
Example
```html
{! layout|post !}
```

This will load the post layout file and put content into ```{{ content }}```.
This is registered through the ```.RegisterLayout()``` function.

## Template Content and Loops

### Single Variable
Example
```html

{{ var|name }}


```

Will produce
```html

Peter


```

### Indexed Variable
Example
```html

{{ var|names|2 }}


```

Will produce
```html

Molly


```

### Function Call
Example
```html

{{ func|getName }}


```

Will produce
```html

Peter


```

### Function Call with Parameters
Example
```html

{{ func|getNameAndAge|"Peter",37 }}


```

Will produce
```html

Peter, 37


```

### Function Call with Parameters, using Reflection
Example
```html

{{ func|getNameAndAge|"Peter",37 }}


```

Will produce
```html

Peter, 37


```

### Check if Variable Exists
Example
```html

{% if name %}Hi {{ var|name }}{% end %}


```

Will produce
```html

Peter


```

### Check if Multiple Variables Exists
Example
```html

{% if name and age %}Hi {{ var|name }}, {{ var|age }}{% end %}


```

Will produce
```


```

### Reverse If-Check
Example
```html

{% if not name %}Something something darkside..{% end %}


```

Will produce
```html

Something something darkside..


```

### Check if Variable is Equal to Something
Example
```html

{% if name == "Peter" %}Hi Peter{% end %}


```

Will produce
```html

Peter


```

### Check if Multiple Variables are Equal to Something
Example
```html

{% if name == "Peter" and age == 37 %}Hi Peter{% end %}


```

Will produce
```html

Peter


```

```html

{% if name == "Peter" or age == 37 %}Hi Peter{% end %}


```

Will produce
```html

Peter


```

### Reverse If-Check
Example
```html

{% if name not "Peter" %}Where did Peter go?{% end %}


```

Will produce
```html

Where did Peter go?


```

### If and Else
Example
```html

{% if name %}Variable exists and is {{ var|name }}{% else %}Variable does not exists{% end %}


```

Will produce
```html

Peter


```

### Do a Loop
Example
```html


    {% loop people %}
  • {{ var|%index }}

  • {% end %}

```

Will produce
```html


  • Peter

  • Parker

  • Molly


```

### Do a Fixed Loop
Example
```html


    {% loop people steps 0,1 %}
  • {{ var|name }}

  • {% end %}

```

Will produce
```html


  • Peter

  • Parker


```

### Do a Nested Loop
Example
```html

{% if companies %}

    {% end %}
    {% loop companies %}

  • {{ var|name }}


    {% if people %}
      {% end %}
      {% loop people %}
    • {{ var|%index }}

    • {% end %}
      {% if people %}
    {% end %}

  • {% end %}
    {% if companies %}
{% end %}
```

Will produce
```html



  • Microsoft



    • Peter

    • Parker




  • Apple



    • Molly

    • Holly




```

## Template Functions

### Count
Example
```html

{% if count(members) > 1 %}More than one member!{% end %}


```