Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
555 views
in Technique[技术] by (71.8m points)

playframework 2.0 - Play 2.0 Framework external Model in Template

Is it possible in Play 2.0, to make use of external model objects in a template?

I can reference model objects from another jar in a Controller class. I don't know how to reference external model objects inside the Play 2.0 template files.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No problem. First, add the class to your classpath, either by adding the jar to the lib dir or through the "managed dependencies" in the projects/Build.scala. Make sure to have fully qualified name when declaring your model class in the template view file. Inside the template, you can reference any public method or member.

@(varName : fully.qualified.name.MyClass)
<h1>@varName.myMember</h1>
<h1>@varName.myMethod</h1>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...