1

I have problems to write reusable code in scala.

If i have something like

@helper.form(action = routes.Guides.addComment(category,title)) {

Is there a way to replace it with a variable?

pseudo code

@(func : Function)
@helper.form(action = func) {

Edit:

Oh.... now it's kinda obvious. The function itself should return a string , so I guess i can just say something like this

@(func :String)
..

.

return ok (form.render(routes.Guides.test()))

Testing it now

2 Answers 2

2

May I suggest an alternative? Use Call directly.

@(route: Call)

@helper.form(action = route) {
  ...
}

In Scala, you could even pass only a part of the route and fill the rest from the controller (very useful when you're using pagination).

Sign up to request clarification or add additional context in comments.

2 Comments

Can you explain this a little how to use this for pagination?
Can you ask it in a separate question please?
2

figured it out.

with

routes.Guides.test().url

you get the url and then you can use it as a parameter

for example

@guidesComment((routes.Guides.addComment(ug.category,ug.title)).url)

guidesComment looks like this

@(func: String)

Then use it like this

<form action="@func" method="POST">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.