简体   繁体   中英

Integrating a runtime splice with a Snap/Heist app

I'm putting together a simple Snap app using Heist templates. I want to print the request url into the page. However, instead of running my splice, the output just has the splice tag. 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:

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

<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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM