Re: Play 2.0: how to reference external tags from a .scala.html file?

84 views
Skip to first unread message

DroidDev

unread,
Nov 3, 2012, 9:56:48 AM11/3/12
to play-fr...@googlegroups.com
Hi Matt, and thanks for the info. I tried the setup you suggested (split my single tagfile into two separate files containing just one tag def each, and moved them under a new views subdir) but even after running "play clean-all" and recompiling the app I'm still seeing that "not found" compilation error for my external tags.
Continuing to investigate...



On Friday, November 2, 2012 3:27:05 PM UTC-4, Matt wrote:
The way we've handled a similar desire in our project is to create a folder in 'views' called 'customhelpers'.  in the custom helpers folder we put a file for each of the snippets we want, (e.g., extending to your case they would be called mytag.scala.html) Then, yes the references need to be imported into the view that references them.  (e.g., at the top of your mymain.scala.html, below the parameter list -- if you needed one -- put the line:

@import views.html.customhelpers._

and then you can call your helper in mymain with:

@mytag()

Maybe not exactly the functionality you wanted, but hopefully that helps.
Matt

On Thursday, November 1, 2012 1:47:53 AM UTC-3, DroidDev wrote:
I'm fairly new to Play 2.0 and I'm trying to create HTML snippets that can be embedded/included in other .scala.html files. Basically I need to be able to reference external tags from other .scala.html files.
I have the following two tags defined in "tagsfile.scala.html" :

@myTag1 = {
<!--  a bunch of html LIST code goes here -->
}

@myTag2 = {
<!--  a bunch of html LIST code goes here -->
}


and in "mymain.scala.html" I have references to those two externally-defined tags :

<ul> <!--  split data into 2 external includes to prevent Java class size limit violation  -->
       @myTag1 ()
       @myTag2 ()
</ul>

I referenced the external tags as Scala functions, but still the app does not compile. I get a Compilation error : "not found: value myTag1".

I checked my '\target\scala-2.9.1\src_managed\main\views\html' directory, and it does indeed contain both .scala.html files.
In Play 2.0, am I supposed to do some sort of "import" or "include" before referencing those two tags?
Anyone have an idea how to properly reference external tags?

Thnx.

virtualeyes

unread,
Nov 3, 2012, 5:14:57 PM11/3/12
to play-fr...@googlegroups.com
likely an error somewhere in your helper method(s)

debugging in template layer is...not fun, but same in Scalatra/Scalate, Lift, etc., template layer seems to have pretty much zero IDE support in Scala land.

At any rate, comb through your helpers I'd say...

Johan Andren

unread,
Nov 4, 2012, 10:22:07 AM11/4/12
to play-fr...@googlegroups.com
A hint for figuring this out is that you can check out the directory where the html-templates are compiled to, and see if that gives you any hints regarding wrong package names etc. The directory to look in is target/scala-2.9.1/classes_managed/views/html/




DroidDev

unread,
Nov 4, 2012, 8:18:53 PM11/4/12
to play-fr...@googlegroups.com
Thnx. I looked for that directory - 'classes_managed' - but it was never generated (perhaps due to the compilation error?).
I did however find 'src_managed', and drilled down to the 'html' directory. AFAICS all the scala files are present; no sign of any errors there so far.

DroidDev

unread,
Nov 4, 2012, 8:23:13 PM11/4/12
to play-fr...@googlegroups.com
By 'helper' methods you mean those in Application.java and the contents of conf/routes?
If there are other helper methods I should be looking at, pls advise. Thnx.

DroidDev

unread,
Nov 7, 2012, 1:39:23 PM11/7/12
to play-fr...@googlegroups.com
Folks, thnx for all  your comments. Problem is now resolved.

Two things:
- I had old scala.html file versions hanging around under my views directory. These files were oversized and caused continual Java class size compile errors even though they didn't appear in my conf file.
- In my main scala.html file I was referencing the actual *tag* defined within the external scala.html files as Scala functions instead of just referencing the *names* of the external files as Scala functions.

(I was somehow under the newbie impression that only those scala.html files actually *defined* in conf/routes were actually compiled :-) Didn't realize that ALL files in the physical directories would be compiled.)
Reply all
Reply to author
Forward
0 new messages