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

Declare a variable inside an edge file #27

Closed
RandallFlagg opened this issue Feb 22, 2018 · 3 comments
Closed

Declare a variable inside an edge file #27

RandallFlagg opened this issue Feb 22, 2018 · 3 comments
Assignees
Milestone

Comments

@RandallFlagg
Copy link

RandallFlagg commented Feb 22, 2018

Hi,

First of all thanks for this project and the entire AdonisJS ecosystem.
I read the docs but couldn't find how to declare a variable inside an edge file.
I would like to define an items constant and use it inside a loop.
then I would like to display the value and manipulate the value.

Here is an example:

file.edge

<script>
const items = ["A","B","C"];
<script>
<select>
      @each(item in items)
        <option value="{{item.toLowerCase()}}">{{item}}</option>
      @endeach
</select>

Thanks in advance

@RandallFlagg RandallFlagg changed the title Declare a variable Declare a variable inside an edge file Feb 22, 2018
@thetutlage
Copy link
Member

I am not sure from where you got this syntax. Edge is a javascript file and hence, thing slike const doesn't work.

Use the @set tag.

<select>
@set('items', ['A', 'B', 'C'])
      @each(item in items)
        <option value="{{item.toLowerCase()}}">{{item}}</option>
      @endeach
</select>

Also it is recommended to pass the values when you render the view and do not set too many variables within the template.

@RandallFlagg
Copy link
Author

RandallFlagg commented Feb 23, 2018

This is exactly what I was looking for.
The syntax was made up by me hoping you will understand. and you did! :)

I can't seem to find the @set in the documentation.
Can you please point me to the correct page?

Thanks

@thetutlage thetutlage self-assigned this May 23, 2018
@thetutlage thetutlage added this to the 2.0 milestone May 23, 2018
@cindrmon

This comment has been minimized.

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

3 participants