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

haskell-哈姆雷特html没有为我的家庭路由处理程序正确注册或标记

(haskell - Hamlet html not registering or tags correctly for my home route handler)

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

由于某种原因<head>,我网站首页标签未按我希望的方式处理。这是我从firefox获得的网站源代码。请注意,第一个head和title标签为空:

<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>
...

这是此路由处理程序的Haskell代码。对我来说,我已经清楚地表明,我要在head标签中指定title和meta标签。上面的HTML似乎与此代码不一致。

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;
}
|]

我不知道问题是什么。

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

如果你只是从落HTMLwhamlet直接defaultLayout,它会在toWidget等的<body>特别是标题,请使用setTitle进行设置。对于剩余的其他内容<head>(例如你的meta标签),请将其hamlet准引号包裹在中toWidgetHead