<commit_before><!--
layout: documentation.html
-->
# Layouts

A layout is a [Twig](http://twig.sensiolabs.org) template.

## Fallback logic

The used layout is determined by the following logic.

If node type is _Homepage_:
 1. ```index.html```
 2. ```_default/list.html```
 3. ```_default/page.html```

If node type is _Section_:
 1. ```section/$section.html``` (Where ```$section``` is the Section name)
 2. ```_default/section.html```
 3. ```_default/list.html```

If node type is _Taxonomy_:
 1. ```taxonomy/$singular.html``` (Where ```$singular``` is the taxonomy name)
 2. ```_default/taxonomy.html```
 3. ```_default/list.html```

If node type is _Terms_:
 1. ```taxonomy/$singular.terms.html``` (Where ```$singular``` is the taxonomy name)
 2. ```_default/terms.html```

Otherwise:
 1. ```$section/page.html``` (Where ```$section``` is the Section name)
 2. ```$section/$layout.html``` (Where ```$layout``` is the layout name)
 3. ```$layout.html```
 4. ```page.html```
 5. ```_default/page.html```

## Variables

### Site

Contains all variables under _site_ key in configuration.

| Variable      | Description       |
| ------------- | ----------------- |
| site.menus    | Menus collections |
| site.pages    | Pages collections |

Menu entry keys:

| Variable               | Description  |
| ---------------------- | ------------ |
| site.menus._id_.name   | Entry name   |
| site.menus._id_.url    | Entry URL    |
| site.menus._id_.weight | Entry weight |

### Page

Contains all page variables and those set in the page's front matter.

| Variable        | Description                      | Example       |
| --------------- | -------------------------------- | ------------- |
| page.title      | Title                            | "Post 1"      |
| page.content    | HTML content                     | _HTML_        |
| page.section    | Section                          | "blog"        |
| page.id         | Unique id                        | "blog/post-1" |
| page.pathname   | Full path                        | "blog/post-1" |
| page.path       | Path                             | "blog"        |
| page.name       | Name                             | "post-1"      |
| page.pages      | Pages collection (for node page) | _Collection_  |
| page.tags       | Tags array                       | [Ta, Tb]      |
| page.categories | Categories array                 | [Ca, Cb]      |
| ...             |                                  |               |

### Pagination

| Variable              | Description               |
| --------------------- | ------------------------- |
| page.pagination.pages | Paginated pages           |
| page.pagination.prev  | Path to the previous page |
| page.pagination.next  | Path to the next page     |

### Taxonomy

| Variable      | Description                 |
| ------------- | --------------------------- |
| page.singular | Taxonomy name               |
| page.plural   | Taxonomy name (plural form) |
| page.terms    | Path to the next page       |

### PHPoole

| Variable          | Description                 |
| ----------------- | --------------------------- |
| phpoole.url       | URL to the official website |
| phpoole.version   | Current version             |  
| phpoole.poweredby | "PHPoole v" + version       |

## Example

```html
<h1>{{ page.title }} | {{ site.title }}</h1>
<span>{{ page.date|date("j M Y") }}</span>
<b>{{ page.content }}</p>
<b>{{ page.customvar }}</p>
```

## Twig

### Functions

#### _url_

Creates an URL.
```
{{ url(page) }}
{{ url('tags/' ~ tag) }}
{{ url(menu.url) }}
{{ url('css/style.css') }}
{{ url('http://narno.org') }}
```

#### _minify_

Minify a CSS or a Javascript file.
```
{{ minify('css/style.css') }}
{{ minify('js/script.js') }}
```

### Filters

#### _excerpt_

Truncates a string to 450 char and adds '…'.
```
{{ string|excerpt }}
```

#### _sortByTitle_

Sorts a pages collection by title.
```
{{ pages|sortByTitle }}
```

#### _sortByDate_

Sorts a pages collection by date.
```
{{ pages|sortByDate }}
```

#### _sortByWeight_

Sorts a menu entries collection by weight.
```
{{ menu|sortByWeight }}
```

#### _filterBy_

Filters a pages collection by variable name.
```
{{ pages|filterBy('section', 'blog') }}
```<commit_msg>Update 3.Layouts.md<commit_after><!--
layout: documentation.html
-->
# Layouts

A layout is a [Twig](http://twig.sensiolabs.org) template.

## Fallback logic

The used layout is determined by the following logic.

If node type is **_Homepage_**:
 1. ```index.html.twig```
 2. ```_default/list.html.twig```
 3. ```_default/page.html.twig```

If node type is **_Section_**:
 1. ```section/$section.html.twig``` (Where ```$section``` is the Section name)
 2. ```_default/section.html.twig```
 3. ```_default/list.html.twig```

If node type is **_Taxonomy_**:
 1. ```taxonomy/$singular.html.twig``` (Where ```$singular``` is the taxonomy name)
 2. ```_default/taxonomy.html.twig```
 3. ```_default/list.html.twig```

If node type is **_Terms_**:
 1. ```taxonomy/$singular.terms.html.twig``` (Where ```$singular``` is the taxonomy name)
 2. ```_default/terms.html.twig```

Otherwise:
 1. ```$section/page.html.twig``` (Where ```$section``` is the Section name)
 2. ```$section/$layout.html.twig``` (Where ```$layout``` is the layout name)
 3. ```$layout.html.twig```
 4. ```page.html.twig```
 5. ```_default/page.html.twig```

## Variables

### Site

Contains all variables under _site_ key in configuration.

| Variable      | Description       |
| ------------- | ----------------- |
| site.menus    | Menus collections |
| site.pages    | Pages collections |

#### _site.menus_

| Variable               | Description  |
| ---------------------- | ------------ |
| site.menus.`id`.name   | Entry name   |
| site.menus.`id`.url    | Entry URL    |
| site.menus.`id`.weight | Entry weight |

### Page

Contains all _page_ variables and those set in the page's front matter.

| Variable        | Description                      | Example       |
| --------------- | -------------------------------- | ------------- |
| page.title      | Title                            | "Post 1"      |
| page.content    | HTML content                     | _HTML_        |
| page.section    | Section                          | "blog"        |
| page.id         | Unique id                        | "blog/post-1" |
| page.pathname   | Full path                        | "blog/post-1" |
| page.path       | Path                             | "blog"        |
| page.name       | Name                             | "post-1"      |
| page.pages      | Pages collection (for node page) | _Collection_  |
| page.tags       | Tags array                       | [Ta, Tb]      |
| page.categories | Categories array                 | [Ca, Cb]      |
| ...             |                                  |               |

#### Pagination

| Variable              | Description               |
| --------------------- | ------------------------- |
| page.pagination.pages | Paginated pages           |
| page.pagination.prev  | Path to the previous page |
| page.pagination.next  | Path to the next page     |

#### Taxonomy

| Variable      | Description                 |
| ------------- | --------------------------- |
| page.singular | Taxonomy name               |
| page.plural   | Taxonomy name (plural form) |
| page.terms    | Path to the next page       |

### PHPoole

| Variable          | Description                 |
| ----------------- | --------------------------- |
| phpoole.url       | URL to the official website |
| phpoole.version   | Current version             |  
| phpoole.poweredby | "PHPoole v" + version       |

## Example

```html
<h1>{{ page.title }} | {{ site.title }}</h1>
<span>{{ page.date|date("j M Y") }}</span>
<b>{{ page.content }}</p>
<b>{{ page.customvar }}</p>
```

## Functions

### _url()_

Create an URL.
```html
{{ url(page) }}
{{ url('tags/' ~ tag) }}
{{ url(menu.url) }}
{{ url('css/style.css') }}
{{ url('http://narno.org') }}
```

### _minify()_

Minify a CSS or a Javascript file.
```html
{{ minify('css/style.css') }}
{{ minify('js/script.js') }}
```

### _readtime()_

Return read time, in minutes.
```html
{{ readtime(page.content) }} min
```

## Filters

### _excerpt_

Truncate a string to 450 char and adds '…'.
```html
{{ string|excerpt }}
```

### _sortByTitle_

Sort a pages collection by title.
```html
{{ pages|sortByTitle }}
```

### _sortByDate_

Sort a pages collection by date.
```html
{{ pages|sortByDate }}
```

### _sortByWeight_

Sort a menu entries collection by weight.
```html
{{ menu|sortByWeight }}
```

### _filterBy_

Filter a pages collection by variable name.
```html
{{ pages|filterBy('section', 'blog') }}
```

### _minifyCSS_

Minify CSS.
```html
{% filter minifyCSS %}
<style>
  html {
    background-color: #fcfcfc;
    color: #444;
    font: 100%/3rem 'Raleway', sans-serif;
  }
</style>
{% endfilter %}
```

### _minifyCSS_

Minify Javascript.
```javascript
{% filter minifyJS %}
<script>
  (function(d) {
    var wf = d.createElement('script'), s = d.scripts[0];
    wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.16/webfont.js';
    s.parentNode.insertBefore(wf, s);
 })(document);
</script>
{% endfilter %}
```
{'fraction_non_alphanumeric': 0.22021426252570067, 'fraction_numerical': 0.006817443999567146, 'mean_word_length': 1.851589015735884, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1255917', 'n_tokens_mistral': 3012, 'n_tokens_neox': 2827, 'n_words': 714}