Skip to content

Commit

Permalink
feat(syntax): out & outn functions to output info within {...}
Browse files Browse the repository at this point in the history
  • Loading branch information
stdword committed Feb 13, 2024
1 parent ed15a94 commit 9b4ec63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 18 additions & 0 deletions docs/reference__syntax.md
Expand Up @@ -122,6 +122,24 @@ No result: ` ``{ c.page.name }`` `
No result:
<!-- tabs:end -->


<!-- div:left-panel -->
But there are the special `out` & `outn` functions to output info within ` ``{...}`` `:

<!-- div:right-panel -->
<!-- tabs:start -->
#### ***Template***
- ` ``{ for (const i of [1, 2, 3]) out(i) }`` `
- ` ``{ for (const i of [1, 2, 3]) outn(i) }`` `

#### ***Rendered***
- 123
- 1 \
2 \
3

<!-- tabs:end -->

<!-- panels:end -->


Expand Down
7 changes: 6 additions & 1 deletion src/extensions/customized_eta.ts
Expand Up @@ -194,7 +194,12 @@ function compileBody(buff) {
// @ts-expect-error
const config = this.config

let returnStr = 'include = undefined; includeAsync = undefined; layout = undefined;\n'
let returnStr = [
'includeAsync = undefined;',
'var out = (x) => {__eta.res+=__eta.f(x)};',
'var outn = (x) => {__eta.res+=__eta.f(x)+"\\n"};',
].join('\n') + '\n'

for (const currentBlock of buff) {
if (typeof currentBlock === 'string') {
const str = currentBlock
Expand Down

0 comments on commit 9b4ec63

Please sign in to comment.