Home Dynamic pass value in a Play2 scala template
Reply: 1

Dynamic pass value in a Play2 scala template

Vinod Published in 2018-02-13 12:27:03Z

I try to dynamically change value of its variable. Once onclick (Change Ticket ID ) button then execute onClickSendEmail and variable value should be change of tickedId. Its unable to update with newTickedId. I tried while create variable using @defining and individual calling by function also. So, Basically I got stuck. how it will be solve.

@(sender: String)
<!--@{var tickedId = "tickedId"}-->

@defining(sender.contains("@")) {isEmail =>
@main((if(isEmail) "Email" else "Chat") + " Messages - " + sender) {

 <a onclick="onClickSendEmail();return false;">
            Change Ticket ID

@defining("getTicketId()") { tickedId =>

                <textarea id="emailArea" cols="100" rows="4" name="emailArea"></textarea>

<script type="text/javascript">
            function onClickSendEmail() {
                tickedId= "NewUpdatedTicketId";
     function getTicketId() {
             return "NewUpdatedTicketId";
Csaba Reply to 2018-02-13 13:00:16Z

You should not mix Twirl templating with Javascript. It's a bad approach. The role for Twirl is to render HTML blocks. You can define conditions and variables here in order to dynamically change the HTML output. While with Javascript you can modify this rendered HTML output without reloading the page.
There are cases where you need to use a Twirl variable in Javascript, then you can do something like:

@(chartData: Html)

    let jsData = @twirlData; // where twirlData is an existing variable

Here's a link where you can read more.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.33347 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO