scottmsul
scottmsul

Reputation: 119

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:

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

Upvotes: 2

Views: 74

Answers (1)

mightybyte
mightybyte

Reputation: 7282

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).

Upvotes: 0

Related Questions