[英]Integrating a runtime splice with a Snap/Heist app
I'm putting together a simple Snap app using Heist templates. 我正在使用Heist模板整理一个简单的Snap应用程序。 I want to print the request url into the page. 我想将请求网址打印到页面中。 However, instead of running my splice, the output just has the splice tag. 但是,除了运行我的接头之外,输出仅包含splice标签。 I feel like I've overlooked something simple, because I can't find any difference between my app and the tutorials I've found. 我觉得我已经忽略了一些简单的事情,因为我找不到我的应用程序与所找到的教程之间的任何区别。
Site.hs: Site.hs:
{-# LANGUAGE OverloadedStrings #-}
module Site
( app
) where
import Data.Monoid
import Snap.Core
import Snap.Snaplet
import Snap.Snaplet.Heist
import Heist
import Application
import Control.Monad.Trans.Class (lift)
import Data.Text.Encoding (decodeUtf8)
import qualified Text.XmlHtml as X
currentPath :: SnapletISplice App
currentPath = do
requestPath <- lift $ withRequest (return . rqURI)
return [X.TextNode $ decodeUtf8 requestPath]
app :: SnapletInit App App
app = makeSnaplet "andrewlorente" "My wubsite" Nothing $ do
let config = mempty {
hcInterpretedSplices = "currentPath" ## currentPath
}
h <- nestSnaplet "heist" heist $ heistInit' "templates" config
return $ App h
index.tpl: 在index.tpl:
<currentPath />
As far as I can tell, the rendered output from visiting the root path / should be something like 据我所知,访问根路径的渲染输出/应该类似于
/
But in fact it is 但实际上是
<currentPath></currentPath>
I'm at my wits' end trying to figure out why my splice isn't run. 我正竭尽全力试图弄清楚为什么我的接头没有打起来。
hnnnnngh hnnnnngh
It's not a problem with the code at all. 这根本不是代码的问题。 I had switched to using a cabal sandbox at some point, but hadn't updated my $PATH so I was still executing an old version of the code that didn't have the splice defined. 我曾经在某个时候改用Cabal沙箱,但没有更新$ PATH,因此我仍在执行未定义接头的旧版本代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.