【问题标题】:Lift render different templates in controllerLift 在控制器中渲染不同的模板
【发布时间】:2014-10-15 21:02:41
【问题描述】:

我有下一个控制器

object MyController extends RestHelper {

  serve {
    case "name" :: name :: _ Get _ =>
      if (name == "adam") {
        //should render template adam.html
      } else {
        //should render other.html
      }       
  }

}

如何解除工作呢?

【问题讨论】:

    标签: lift


    【解决方案1】:

    我认为你应该能够使用这样的东西:

    Templates.apply("adam" :: Nil) match {
      case Full(ns) => XhtmlResponse(ns)
      case _ => NotFoundResponse("404 - Template Not Found")
    }
    

    不过,有两件事 - 如果您只是渲染页面 - 为什么不使用内置于 SiteMap 的lift?它为您处理了很多错误情况等。此外,您可能需要考虑制定这两个不同的规则,以后可能会更容易遵循这样的规则:

     case "name" :: "adam" :: _ Get _ => //render adam.html
     case "name" :: _ :: _ Get _ => //render other
    

    【讨论】:

      猜你喜欢
      • 2011-03-10
      • 2012-07-27
      • 2014-05-23
      • 2012-12-31
      • 2016-07-13
      • 1970-01-01
      • 2018-01-19
      • 2014-11-26
      • 2017-09-30
      相关资源
      最近更新 更多