首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想在Yesod的defaultLayout中添加Lucid

我想在Yesod的defaultLayout中添加Lucid
EN

Stack Overflow用户
提问于 2018-10-29 23:54:49
回答 2查看 176关注 0票数 2

我试图有一个动态的HTML id,用于调制解调器的使用。

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

因为我还没有在哈姆雷特中做到这一点,所以我试着用露西德来做,但这与叶苏德的defaultLayout不相容。

我的目的是:

代码语言:javascript
复制
getSupportR :: CustomerId -> Handler LucidHtml
getSupportR customerId = do
 defaultLayout $ do
    setTitle "Your Licenses"
    toWidget . lucid $ \url ->
      p_ $ a_ [href_ "\\"] "Link to root"

这是错误消息:

代码语言:javascript
复制
• 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

有没有办法把LucidHtml转换成Blaze的Html?

我的全部代码位于:https://github.com/hhefesto/laurus-nobilis,相关文件为/src/Yesod/Lucid.hs和/src/Handler/Support.hs。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-10-30 07:49:01

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

票数 0
EN

Stack Overflow用户

发布于 2018-10-31 21:32:39

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

代码语言:javascript
复制
{-# 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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53055515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档