简体   繁体   中英

How to use Snap/Heist without creating routes automatically for every template

Is it possible to use Snap/Heist in such a way that not every template has an auto-generated route? For example, suppose I have a template called "outline" with an <apply-content/> tag, and a template called "index" which calls <apply template="outline"> . I want the "index" template to be visible under the route "/", and the "outline" template to not have a route. I've tried the following:

  • Calling heistInit and putting both index.tpl and outline.tpl in the templates directory. This automatically creates a route for "outline".

  • Putting outline.tpl in a separate directory and calling addTemplatesAt . This also automatically creates a route for outline .

  • Calling heistInit' instead of heistInit , with an empty Config, as follows:

     h <- nestSnaplet "" heist $ heistInit' "templates (Heist.emptyHeistConfig { Heist.Internal.Types._hcNamespace = "" }) 

Doing the last way means I have to add the routes by hand, which is ok. But even though I could serve the templates using render or heistServeSingle , the templates could not see each other when using <apply> .

I know this feels like only a "minor" issue, I could just let the helper-templates be visible, but to me that feels sloppy. I was curious to see if http://snapframework.com did something to get around this, but it appears they left their helper templates visible, for example: http://snapframework.com/nav

Like Libby said, the intended solution is to prefix template names with an underscore to make them not served. I'm not sure what she's seeing with it actually serving those templates. This line of code does the check:

https://github.com/snapframework/snap/blob/master/src/Snap/Snaplet/HeistNoClass.hs#L320

If this isn't working, then please file a bug with a way for me to reproduce the problem.

The second approach that can be used is to call heistInit' os heistServe doesn't get added for you implicitly. This should have no impact on whether you can see the templates using <apply> because it does not go through a route to retrieve a template. I suspect if you were having trouble there it might be because you used emptyHeistConfig and then didn't set the scTemplateLocations field ( http://hackage.haskell.org/package/heist-1.0.1.0/docs/Heist-Internal-Types.html#v:_scTemplateLocations ).

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