> For the complete documentation index, see [llms.txt](https://danila-korotkov.gitbook.io/front-end-patterns/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://danila-korotkov.gitbook.io/front-end-patterns/ghost/sozdanie-svoei-temy/cikly-usloviya-i-funkcii.md).

# Циклы, условия и функции

Все циклы объявляются в файлах `hbs` через синтаксис - {{ #цикл/условие }}

### #foreach

{% code title="foreach" %}

```html
{{#foreach posts}}
    {{ title }}
{{/foreach}}
```

{% endcode %}

Количество выводимых постов настраивается в параметре `"config"` файла `package.json`

### #if

```html
{{#if meta_description}}
   {{meta_description}}
{{else}}
   {{excerpt words="40"}}...
{{/if}}
```

### #get

&#x20;Получает набор для дальнейшего использования

Возможные наборы:

**posts** - посты

**tags** - тэги&#x20;

```html
{{#get "posts" limit="5" as |recent|}}
      <section>
         <h3>Recent Posts</h3>
         <ul>
            {{#foreach recent}}
            <li>
               <a href="{{url}}">{{title}}</a>
            </li>
            {{/foreach}}
         </ul>
      </section>
   {{/get}}
```

## Переменные для функций и вывода

**words** - ограничивает вывод содержимого (excerpt words="40")

**limit** - ограничивает вывод набора

## Вывод шаблонов

**{{< имя}}** - передает содержимое файла в шаблон "имя" (находится в самом шаблоне). Там содержимое шаблона выводим через {{body}}

**{{> имя}}** - вызываем шаблон "имя" находящийся в папке "Partials".&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://danila-korotkov.gitbook.io/front-end-patterns/ghost/sozdanie-svoei-temy/cikly-usloviya-i-funkcii.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.
