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

  • SEARCH
  • Home
  • 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 8931309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:05:12+00:00 2026-06-15T09:05:12+00:00

Background : I am studying how Hamlet works, with WAI, but without Yesod. I

  • 0

Background: I am studying how Hamlet works, with WAI, but without Yesod. I have no grasp of Template Haskell, but before I dive into it, I am wondering if there is a known/quick solution for this task.

Specifics: I would like to know how to change the NewlineStyle in the context of a Hamlet quasiquote.

Exploration: I believe it has something to do with a function call that looks like this

hamletWithSettings 
htmlRules 
HamletSettings 
  {
      hamletDoctype             = "<!DOCTYPE html>"
     ,hamletNewlines            = DefaultNewlineStyle
     ,Hamlet.hamletCloseStyle   = htmlCloseStyle -- this fn is in a hidden module 
     ,Hamlet.hamletDoctypeNames = []
  }   

… however, I don’t know how to write the code that does this, in the context of the quasiquote.

Here is the working code, which I hope to modify:

{-# LANGUAGE OverloadedStrings #-} 
{-# LANGUAGE QuasiQuotes #-}

import Control.Monad.Trans.Resource
import Text.Hamlet                                  as Hamlet
import qualified Data.ByteString.Lazy.Char8         as ByteString
import qualified Network.Wai                        as Wai
import qualified Network.HTTP.Types                 as Http
import qualified Network.Wai.Handler.Warp           as Warp
import qualified Text.Blaze                         as Blaze 
import qualified Text.Blaze.Html.Renderer.String    as Blaze
-------------------------------------------------------------------------------
main :: IO ()
main = Warp.run 3000 application
-------------------------------------------------------------------------------
application :: Wai.Request -> ResourceT IO Wai.Response
application request = return $
    case (head $ Wai.pathInfo request) of
        "html" ->   
            Wai.responseLBS Http.status200  []  $ ByteString.pack 
                                                $ Blaze.renderHtml 
                                                $ htmlDoc -- defined below
        "d3" ->     
            Wai.ResponseFile Http.status200 [] "./d3.v2.min.js" Nothing
        _ ->        
            Wai.responseLBS Http.status400  [] "" 
-------------------------------------------------------------------------------
htmlDoc :: Hamlet.Html
htmlDoc = [shamlet|
!!!
<html>
    <head>
        <title>Study Graph
        <!-- <link rel="stylesheet" type="text/css" href="/css"> -->
        <script type="text/javascript" src="/d3" />
        <style>
        <script>
            window.onload = function()
            {
                svg = 
                    d3  .select("body")
                        .append("svg")
                        .attr("width", "100%")
                        .attr("height", "100%")
                /* SOLUTION to strawman: a solitary "\" on this code row, will render a single newline character; i.e. "\n\\\n" renders as "\n" */
                svg .selectAll("circle")
                    .data([ {"cx": 1.0, "cy": 1.1, "r":1}, 
                            {"cx": 2.0, "cy": 2.5, "r":0.9} ])

            }
    <body>
|]
-------------------------------------------------------------------------------

Thanks in advance for any assistance, insults, or other commentary.

  • 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-06-15T09:05:15+00:00Added an answer on June 15, 2026 at 9:05 am

    The basic idea would be to create a new identifier, e.g.:

    myHamlet = hamletWithSettings 
      htmlRules 
      (   HamletSettings 
        "<!DOCTYPE html>" 
        DefaultNewlineStyle htmlCloseStyle doctypeNames )
    

    Then use myHamlet in place of hamlet, e.g.:

    htmlDoc = [myHamlet|...|]
    

    Due to the stage restriction, you’ll likely need to declare myHamlet in a different module to the one where you use it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently studying bitwise arithmetic. It's really easy, because I have some CS background. But
Background: I would like to dismiss a modalView that I have presented earlier and
I am studying blackberry webworks. I have done one demo, where there is one
Background: I have a Visual Studio solution consisting of a website + REST web-service
I'm studying C++ right now, coming from a background in Python, and I'm having
I'm studying jQuery with this tutorial, but one of examples doesn't work. <html> <head>
First of all I am mainly with a JSF background. I have started recently
Background: I have a performance-critical query I'd like to run and I don't care
I have just started studying JOGL and there is one problem. Below is simple
Background: I have an opc tag whose value is a 32 bit floating point

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.