mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-17 14:30:34 +08:00
74 lines
2.3 KiB
YAML
74 lines
2.3 KiB
YAML
# Copyright 2020-2021 Lowdefy, Inc
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
_ref:
|
|
path: templates/operators.yaml.njk
|
|
transformer: templates/operatorsMethodTransformer.js
|
|
vars:
|
|
pageId: _nunjucks
|
|
pageTitle: _nunjucks
|
|
filePath: operators/_nunjucks.yaml
|
|
types: |
|
|
```
|
|
(template: string): string
|
|
(arguments: {template: string, on: object}): string
|
|
```
|
|
description: |
|
|
The `_nunjucks` hydrates a [Nunjucks](https://mozilla.github.io/nunjucks/) template.
|
|
|
|
If called with a string argument, the template variables are the values in `state`. Otherwise template variables can be specified using the `on` argument.
|
|
arguments: |
|
|
###### string
|
|
The template to hydrate. The template variables used are the values in state
|
|
|
|
###### object
|
|
- `template: string`: The template to hydrate.
|
|
- `on: object`: The template variables to use when hydrating the template.
|
|
examples: |
|
|
###### Populate a template from values in `state`:
|
|
```yaml
|
|
_nunjucks: Hello {{ name }}
|
|
```
|
|
Returns: `"Hello Steven"` if the value of name in state is `"Steven"`.
|
|
|
|
###### Populate a markdown template with different values:
|
|
Assuming `get_items` returns:
|
|
```yaml
|
|
- name: Coca Cola
|
|
description: The original.
|
|
- name: Pepsi
|
|
description: The same but different.
|
|
```
|
|
|
|
```yaml
|
|
_nunjucks:
|
|
template: |
|
|
### {{ title }}
|
|
|
|
{% for item in item_list %}
|
|
- {{ item.name }}: {{ item.description }}
|
|
{% endfor %}
|
|
on:
|
|
title: Soft drinks
|
|
items:
|
|
_request: get_items
|
|
```
|
|
Returns:
|
|
```markdown
|
|
### Soft drinks
|
|
|
|
- Coca Cola: The original.
|
|
- Pepsi: The same but different.
|
|
```
|