0

I am trying to set a value to a variable in play template and access it in the controller. For ex, in homepage.scala.html, I would like to set a pageName variable a value as "homepage.scala.html". Once I set this value in the play template, I want to access it in my controller which is presently in Java.

How do I achive this?

I will then be migrating the controller to scala. How do access the pageName value in scala controller?

Why I am trying to do this?: I am trying to apply Play Aloha editor to my application How to integrate the Aloha Wysiwyg Editor with Play! Framework. Here, when a static content on the page is edited, the page name is passed to central controller which then modifies the actual template page or even message resource to update the static content. If I can't or shouldn't pass the page name to the controller then how do I achieve this?

Many thanks.

texpert
  • 185
  • 1
  • 3
  • 14
  • 2
    You can't, and you don't want to, that's not how MVC works. The only thing that should come out of your view is HTML. It sounds to me like you have logic in your view that belongs in the controller. – wingedsubmariner May 22 '14 at 15:57
  • It sounds like you want live-editing of your templates. I think you would do this via AJAX calls from the client to a separate controller method, e.g. `public static Result index() {...}` & `public static Result updateIndex() {...}` – 2manyprojects May 23 '14 at 13:54
  • FWIW I think ^ describes how the sample project you link to works, (based on a 30s perusal of the codebase, so I could be off base: patches welcome) there is a controller method for rendering the initial view and another method for saving the aloha updates. – 2manyprojects May 23 '14 at 13:59

1 Answers1

0

At a general level, your templates should be acting like pure functions, without containing any state. But based on what you're asking, assuming your view is in scope as views.html.homepage, you could do something like views.html.homepage.getClass.getName

acjay
  • 34,571
  • 6
  • 57
  • 100