Warm tip: This article is reproduced from serverfault.com, please click

Hamlet html not registering or tags correctly for my home route handler

发布于 2020-11-29 00:28:49

For some reason the <head> tag for the home of my website is not being processed the way I would like. Here is the source code of my site that I get from firefox. Please note that the first head and title tags are empty:

<html><head><title></title><style>form{margin:0 auto;width:250px}</style></head><body><head><title>Fishing Weather Hub </title>
<meta name="description" content="Completely free fishing weather data provided by NOAA and Open Weather Maps. Designed to be simple and easy to use.">
<meta name="keywords" content="fishing weather,fishing,weather">
<meta name="robots" content="index,follow">
</head>
<header><center style="font-size:30px">Fishing Weather Hub</center>
...

Here is the Haskell code for this route handler. To me I have made it clear that within the head tag I would like to specify the title and meta tags. The HTML above does not seem to align with this code.

getHomeR :: Handler Html    
getHomeR = do

  clearSession

  key <- liftIO $ MYP.randomString 9

  setSession "cache_key" (T.pack key) 

  sess <- getSession

  -- Generate the location form
  (widget, enctype) <- generateFormPost $ renderDivs locationForm

  defaultLayout $ do
    [whamlet|
<head>
  <title>Fishing Weather Hub 
  <meta name="description" content="Completely free fishing weather data provided by NOAA and Open Weather Maps. Designed to be simple and easy to use.">
  <meta name="keywords" content="fishing weather,fishing,weather">
  <meta name="robots" content="index,follow">
<header>
  <center style="font-size:30px">Fishing Weather Hub
  <br>
  <form method=post action=@{ProcessLocationFormR} enctype=#{enctype}>
    ^{widget}
    <button>Submit
  <a href="https://www.anglerwise.com/2010/02/09/how-does-barometric-pressure-affect-fishing/">How does barometric pressure affect fishing?
|]
    --CSS
    toWidget
      [lucius|
form {
margin: 0 auto;
width:250px;
}
|]

I do not know what the problem is.

Questioner
Nicholas Hubbard
Viewed
0
Joseph Sible-Reinstate Monica 2020-11-29 10:41:35

If you just drop HTML from whamlet directly in defaultLayout, it goes in toWidget and so in the <body>. For the title in particular, use setTitle to set it. For the rest of the stuff that goes in <head> (like your meta tags), wrap their hamlet quasi-quotes in toWidgetHead.