snapframework / snap

Top-level package for the official Snap Framework libraries, includes the snaplets API as well as infrastructure for sessions, auth, and templates.
http://snapframework.com/
BSD 3-Clause "New" or "Revised" License
455 stars 68 forks source link

Bind doesn't work as expected when rendering templates pulled in via addTemplatesAt #107

Closed cimmanon closed 10 years ago

cimmanon commented 10 years ago

I have a set of templates being pulled in using addTemplatesAt that exist outside of my default template directory:

app :: SnapletInit App App
app = makeSnaplet "app" "An snaplet example application." Nothing $ do
    h <- nestSnaplet "heist" heist $ heistInit' "templates" defaultHeistState
    s <- nestSnaplet "sess" sess $ initCookieSessionManager "site_key.txt" "sess" (Just 3600)
    d <- nestSnaplet "db" db pgsInit

    addRoutes routes
    addTemplatesAt h "archives" "archives"
    return $ App h s d
    where
        defaultHeistState = mempty
            { hcInterpretedSplices = defaultInterpretedSplices
            , hcLoadTimeSplices = defaultLoadTimeSplices
            }

I've setup a simple handler to render those templates like so:

archiveServe :: AppHandler ()
archiveServe = do
    url <- withRequest (return . rqPathInfo)
    render  "archives/" <> url <> "index"

If I attempt to use bind within my template, the content within the bind tag is removed from the template as expected. However, I am unable to apply it:

<bind tag="foo">1234</bind>
<foo />

If I switch to using renderWithSplices, then bind works as expected:

archiveServe :: AppHandler ()
archiveServe = do
    url <- withRequest (return . rqPathInfo)
    let
        splices = return ()
        template = "archives/" <> url <> "index"
    renderWithSplices template splices 
cimmanon commented 10 years ago

Ok, so apparently the problem isn't with bind/apply, but with changes to my template not being detected since it lives outside of the directories that get watched for changes. Switching to renderWithSplices appeared to make things work because the templates were reloaded with my application. I suppose this is expected behavior.