我想将 Lucid 添加到 Yesod 的 defaultLayout
I would like to add Lucid into Yesod's defaultLayout
我正在尝试使用动态 HTML id 来使用模态。
如果哈姆雷特接受类似 [hamlet| <div .modal .fade ##{modalIdFunction i}> |]
的东西,基本上我的问题就会得到解决
由于我无法在 Hamlet 中做到这一点,我正在尝试使用 Lucid 来做到这一点,但它与 Yesod 的 defaultLayout 不兼容。
这是我的意图:
getSupportR :: CustomerId -> Handler LucidHtml
getSupportR customerId = do
defaultLayout $ do
setTitle "Your Licenses"
toWidget . lucid $ \url ->
p_ $ a_ [href_ "\"] "Link to root"
这是错误消息:
• Couldn't match type ‘blaze-markup-0.8.2.1:Text.Blaze.Internal.MarkupM
()’
with ‘HtmlT Identity ()’
Expected type: HandlerFor App LucidHtml
Actual type: HandlerFor App Html
有没有办法将 Lucid 的 LucidHtml 转换为 Blaze 的 Html?
我的全部代码位于:https://github.com/hhefesto/laurus-nobilis
相关文件是 /src/Yesod/Lucid.hs 和 /src/Handler/Support.hs
由于 lucid Html
和 blaze Html
是完全不同的类型,您唯一的方法是将一个呈现为文本并将其作为预转义 HTML 插入到另一个。类似于 Blaze.preEscapedToHtml . Lucid.renderText
.
为了完整起见,这是集成到代码中的 arrowd 的答案:
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Handler.Support where
import Import hiding
import Yesod.Lucid
import Lucid hiding (Html)
import qualified Lucid as L
import Text.Blaze.Html
getSupportR :: CustomerId -> Handler Html
getSupportR customerId = do
lucidHtml <- lucid $ \url ->
p_ $ a_ [href_ "\"] "link to root"
defaultLayout $ do
setTitle "Your Licenses"
toWidget . preEscapedToHtml . renderText $ lucidHtml
我正在尝试使用动态 HTML id 来使用模态。
如果哈姆雷特接受类似 [hamlet| <div .modal .fade ##{modalIdFunction i}> |]
由于我无法在 Hamlet 中做到这一点,我正在尝试使用 Lucid 来做到这一点,但它与 Yesod 的 defaultLayout 不兼容。
这是我的意图:
getSupportR :: CustomerId -> Handler LucidHtml
getSupportR customerId = do
defaultLayout $ do
setTitle "Your Licenses"
toWidget . lucid $ \url ->
p_ $ a_ [href_ "\"] "Link to root"
这是错误消息:
• Couldn't match type ‘blaze-markup-0.8.2.1:Text.Blaze.Internal.MarkupM
()’
with ‘HtmlT Identity ()’
Expected type: HandlerFor App LucidHtml
Actual type: HandlerFor App Html
有没有办法将 Lucid 的 LucidHtml 转换为 Blaze 的 Html?
我的全部代码位于:https://github.com/hhefesto/laurus-nobilis 相关文件是 /src/Yesod/Lucid.hs 和 /src/Handler/Support.hs
由于 lucid Html
和 blaze Html
是完全不同的类型,您唯一的方法是将一个呈现为文本并将其作为预转义 HTML 插入到另一个。类似于 Blaze.preEscapedToHtml . Lucid.renderText
.
为了完整起见,这是集成到代码中的 arrowd 的答案:
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Handler.Support where
import Import hiding
import Yesod.Lucid
import Lucid hiding (Html)
import qualified Lucid as L
import Text.Blaze.Html
getSupportR :: CustomerId -> Handler Html
getSupportR customerId = do
lucidHtml <- lucid $ \url ->
p_ $ a_ [href_ "\"] "link to root"
defaultLayout $ do
setTitle "Your Licenses"
toWidget . preEscapedToHtml . renderText $ lucidHtml