Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs/syntax/helpers #22

Open
utterances-bot opened this issue Aug 3, 2020 · 8 comments
Open

docs/syntax/helpers #22

utterances-bot opened this issue Aug 3, 2020 · 8 comments

Comments

@utterances-bot
Copy link

Helpers | SquirrellyJS

Helpers are an easy way to include logic within a template. Conditionals, looping, and partials are all implemented using helpers.

https://squirrelly.js.org/docs/syntax/helpers

Copy link

ilanl commented Aug 3, 2020

It's unclear what's the use here for blocks, also I'm missing the code that relates to this example.

Copy link

ilanl commented Aug 3, 2020

Can a self-closing helper return an array of values?

for example:
data: { languageCodes: ["en", "fr", "es"] }
{{@async helperTranslate(it.languageCodes) /}}
would return ["English", "French", "Spanish"]

Can we nest the result of an helper with another helper?
For example:
{{@helperListAND({{@async helperTranslate(it.languageCodes) /}} ) /}}

@nebrelbug
Copy link
Collaborator

@ilanl you can't nest the result of a helper with another helper. In cases requiring complex logic like that, it's best to move all the logic inside one helper.

A self-closing helper can return an array of values, but it will be automatically turned into a string by Squirrelly when it's interpolated into the template.

@nebrelbug
Copy link
Collaborator

@ilanl blocks are mainly useful when you want to define two "sub-templates" that can be passed into one helper function. For example, the if helper uses blocks:

{{@if(it.someval === "someothervalue")}}
Display this!
{{#else}}
They don't equal
{{/if}}

"Display this!" is inside the default block, passed into the content parameter of a helper function. "They don't equal" is inside a block called else.

The if helper looks through each of its blocks. If the condition is true, it outputs the first block. If the condition is false and there are blocks called elif (else if), it loops through each of those blocks, evaluates whether their condition is true, and if so displays them. If the condition is false and there's a block called else, it outputs that block.

Copy link

tafandi commented May 6, 2023

Is there a way to extend the "each" helper so it can call a callback function on each iteration? The idea is to update a progress bar along the template execution (useful when processing big JSON data) so user will know how long to wait until completion. Thanks

@nebrelbug
Copy link
Collaborator

Copy link

This page is completely unclear to me.

  • In the basic syntax section, where am I using var1, var2?
    • Am I defining {{#helperblock}} and {{/helpername}} in the same file as {{@helpername(parameters) => [var1, var2]}}?
    • Is content goes here the content for the helper definition that would use var2 and var2?
  • In the example section, where is userID being used? Why define it if it's not going to be used in the example?
    • How is the stuff between the portfolio used in the @portfolio helper? I feel like there's a missing example of the actual @portfolio definition here

Copy link

As @theogravity said, I'm a bit confused to. Is there an example on this page that shows the code that defines a helper?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants