简体   繁体   English

如何在不为每个模板自动创建路径的情况下使用捕捉/抢劫

[英]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"> . 例如,假设我有一个带有<apply-content/>标签的名为“ outline”的模板,以及一个名为<apply template="outline">名为“ index”的<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. 调用heistInit并将index.tploutline.tpl放在templates目录中。 This automatically creates a route for "outline". 这将自动为“轮廓”创建路线。

  • Putting outline.tpl in a separate directory and calling addTemplatesAt . outline.tpl放在单独的目录中,然后调用addTemplatesAt This also automatically creates a route for outline . 这也会自动为outline线创建路线。

  • Calling heistInit' instead of heistInit , with an empty Config, as follows: 使用空的Config调用heistInit'而不是heistInit ,如下所示:

     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> . 但是,即使我可以使用renderheistServeSingle提供模板,但使用<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 我很想知道http://snapframework.com是否做了一些事情来解决这个问题,但是看来他们没有看到他们的帮助模板,例如: http : //snapframework.com/nav

Like Libby said, the intended solution is to prefix template names with an underscore to make them not served. 就像Libby所说的那样,预期的解决方案是在模板名称前加上下划线,以使其不被使用。 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 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. 可以使用的第二种方法是调用heistInit' heistServe不会为您隐式添加。 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. 这不会影响您是否可以使用<apply>查看模板,因为它不会通过检索模板的途径。 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 ). 我怀疑您是否遇到麻烦,可能是因为您使用emptyHeistConfig,然后未设置scTemplateLocations字段( http://hackage.haskell.org/package/heist-1.0.1.0/docs/Heist-Internal-Types .html#v:_scTemplateLocations )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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