Getting Started
Request handling
- Routing
- Action Controller
- Resources
- Context
- Request Binding
- Middleware
- Error Handling
- Sessions
- Cookies
Frontend
Database
- Getting started with Pop
- Soda CLI
- Database Configuration
- Buffalo Integration
- Models
- Generators
- Migrations
- Fizz
- Mutations
- Querying
- Raw Queries
- Callbacks
- Scoping
- Associations and Relationships
- One to one associations
- One to many associations
Guides
- API Applications
- File Uploads
- Background Job Workers
- Mailers
- Tasks
- Plugins
- Local Authentication
- Third Party Authentication
- Events
- Go Modules
- Localization
- Logging
- Template Engines
- Testing
- Videos
Deploy
Iterating
Frontend
Iterating
Iterating Through Arrays
When looping through arrays
or slices
, the block being looped through will have access to the “global” context.
The for
statement takes 1 - 2 arguments. When using the two argument version, the first argument is the “index” of the loop and the second argument is the value from the array or slice.
<ul>
<%= for (index, name) in names { %>
<li><%= index %> - <%= name %></li>
<% } %>
</ul>
When using the one argument version the index is omitted and just the value is returned:
<ul>
<%= for (name) in names { %>
<li><%= name %></li>
<% } %>
</ul>
Iterating Through Maps
Looping through maps
using the each
helper is also supported, and follows very similar guidelines to looping through arrays
.
When using the two argument version, the first argument is the key of the map and the second argument is the value from the map:
<ul>
<%= for (key, value) in users { %>
<li><%= key %> - <%= value %></li>
<% } %>
</ul>
When using the one argument version the key is omitted and just the value is returned:
<ul>
<%= for (user) in users { %>
<li><%= user %></li>
<% } %>
</ul>