在play 2框架中创建scala.html文件 [英] create scala.html files in play 2 framework

查看:107
本文介绍了在play 2框架中创建scala.html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望现在更好地解释我的问题,我正在使用play 2框架和java来开发一个带有html5 canvas的草绘系统。

hope to explain my problem better now , I am using play 2 framework with java to develop a sketching system with html5 canvas.

前端将由3个不同的视图(页面)组成。一个用于渲染html5画布,一个用于渲染提交表单和显示标签。第三页作为管理员页面。
想要创建这些视图,并能够从一个渲染的视图或页面导航到另一个。

the front end will be composed of 3 different views (pages). one for rendering the html5 canvas , one for rendering a submit form and display tags. And a third page as an administrator page. want to create these views and be able to navigate from one rendered view or page to another.

很抱歉,如果这是一个基本问题,而是一种新的游戏框架。

Sorry if it is a basic question but kind of new to play framework.

对我有任何建议。

我知道@helper标签已被使用,但似乎不知道如何去做。

I know the @helper tags are used but don't seem to know how to go about it.

谢谢。

推荐答案

您不需要使用 @helper @tags 它们用于在其他模板中包含模板,只需使用常见渲染,首先创建文件:

You don't need to use @helper or @tags they are for including templates in other templates, just use common rendering, first create the files:


  • app / views / canvas.scala.html

  • app / views / edit.scala.html

  • app / views / admin.scala.html

然后在你的 Appliaction 控制器中创建代表每个视图的三个动作

So then in your Appliaction controller create three actions representing each view

public static Result canvas(){
    return(views.html.canvas.render());    
}

public static Result canvas(){
    return(views.html.edit.render());    
}

public static Result canvas(){
    return(views.html.admin.render());    
}

对于每个操作,您还需要创建路线 conf / routes 中将翻译给定URL以正确操作(首先是默认值):

For each action you also need to create a route in conf/routes to 'translate' given URL to proper action (first is default):

GET   /             controllers.Application.canvas()
GET   /edit         controllers.Application.edit()
GET   /admin        controllers.Application.admin()

最后在每个视图中添加该块,以便在每个页面上显示主菜单。注意:使用reverseRouting作为 href 的链接,以确保它们始终正确 - 即使您在路线中更改了某些内容(事实上,在这里您可以使用@tags来包含此内容)阻止从一个文件到多个视图,但现在手动放置):

Finally in each view add that block, to get the 'main menu' displayed on every page. Note: use reverseRouting as a href of links to make sure they are always correct - even if you change something in routes (de facto, here you could use @tags for including this block from one file to many views, however place it manually now):

<div class="main-nav">
    <a href='@routes.Application.canvas()'>Canvas page</a>
    <a href='@routes.Application.edit()'>Edit form</a>
    <a href='@routes.Application.admin()'>Admin area</a>
</div>

您现在有3个操作的基本应用程序样本,单独的视图为每个人。

You have now sample for basic application with 3 actions, with separate view for each.

最后,不要生我的气,但你需要花更多的时间研究官方文档并包含Java示例。我向您展示了基本场景,它允许您在三个页面之间导航,而不是其他任何内容。最有可能的是,它不应该编写工作应用程序,但是描述它没有任何意义 - 正如它在文档中描述并在样本中演示。

At the end, don't be angry with me, but you need to spent more time studying official documentation and included Java samples. I showed you basic scenario, which allows you to navigate between three pages and nothing else. Most probably it's not enought to write working app, however describing it makes no sense - as it's described yet in the docs and demonstrated in samples.

这篇关于在play 2框架中创建scala.html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆