【问题标题】:I would like to add Lucid into Yesod's defaultLayout我想将 Lucid 添加到 Yesod 的 defaultLayout
【发布时间】:2018-10-29 23:54:49
【问题描述】:

我正在尝试使用动态 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

【问题讨论】:

    标签: haskell yesod blaze-html haskell-lucid


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-09
        • 1970-01-01
        • 2021-03-30
        相关资源
        最近更新 更多