Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6618671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:51:55+00:00 2026-05-25T20:51:55+00:00

With the hamlet templating language that comes with yesod, what is the best way

  • 0

With the hamlet templating language that comes with yesod, what is the best way of printing a comma-separated list?

E.g. assume this code which just prints one entry after another, how do I insert commas in between the elements? Or maybe even add an “and” before the last entry:

The values in the list are
$ forall entry <- list
    #{entry}
and that is it.

Some templating languages such as Template Toolkit provide directives to detect the first or last iteration.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:51:56+00:00Added an answer on May 25, 2026 at 8:51 pm

    I don’t think there’s anything built-in like that. Fortunately, it’s easy to use helper functions in Hamlet. For example, if your items are plain strings, you can just use Data.List.intercalate to add commas between them.

    The values in the list are 
    #{intercalate ", " list} 
    and that is it.
    

    If you want to do fancier things, you can write functions to work with Hamlet values. For example, here’s a function which adds commas and “and” between the Hamlet values in a list.

    commaify [x] = x
    commaify [x, y] = [hamlet|^{x} and ^{y}|]
    commaify (x:xs) = [hamlet|^{x}, ^{commaify xs}|]
    

    This uses ^{...} syntax to insert one Hamlet value into another. Now, we can use this to write a comma-separated list of underlined words.

    The values in the list are 
    ^{commaify (map underline list)} 
    and that is it.
    

    Here, underline is just a small helper function to produce something more interesting than plain text.

    underline word = [hamlet|<u>#{word}|]
    

    When rendered, this gives the following result.

    The values in the list are <u>foo</u>, <u>bar</u> and <u>baz</u> and that is it.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Hamlet, $doctype 5 generates <!DOCTYPE html> . The Yesod book says that We
From the Yesod Book . Hamlet automatically has access to the variables in scope
:I have this table: id | name | chapter | book 1 hamlet I
For sorting item names, I want to support numbers correctly. i.e. this: 1 Hamlet
Can anyone point me to an example of how to use Hamlet without Yesod?
Hi I'm very new to yesod and I'm trying to follow this Tutorial but
I noticed radioField gives back a blob that cannot be obviously iterated through via
I tried modifying a Yesod project, and came across a weird error. First I
Ok, so I need to create a command that lists the 100 most frequent
I'm new to SQL and I am having trouble even starting this query. If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.