我想将 Lucid 添加到 Yesod 的默认布局中



我正在尝试为模式的使用提供一个动态HTML id。

基本上,如果哈姆雷特接受[hamlet| <div .modal .fade ##{modalIdFunction i}> |]这样的东西,我的问题就会得到解决

由于我在《哈姆雷特》中没能做到这一点,我试图用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

为了完整起见,这是集成到代码中的箭头的答案:

{-# 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

由于clearidHtml和blazeHtml是完全不同的类型,您唯一的方法是将其中一种类型呈现为文本,并将其作为预转义HTML插入另一种类型。类似Blaze.preEscapedToHtml . Lucid.renderText

最新更新