Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playframework twirl (scala templates) guides

Good day all

note: Play! Framework newbie here.

I am trying to familairze myself using scala templates for a project, but cannot quite seem to get it right, nor do the examples found online always work correctly.

Problem:

I have to have searched for small solutions for a problem, and frequently encounter syntactical errors or the like.

I decided to search for some comprehensive guide to building Scala templates used as views, but found only fragments and pieces of code that may help.

Documentation Provided:

  • Play Scala Documentation

Play provided examples:

  • Examples in Java and Scala

Variables:

  • Declaring variables

  • Declaring Variable 2

Displaying Data:

  • Displaying data using functions

  • Display Items in alternating rows table with indicies

  • Using blocks

  • Displaying Block Scala variables in html see the use of { and }

Passing Data / Objects:

  • Passing objects between views and controllers

Further Reading:

  • Play Google Groups thread

Question:

note: I am asking this only since I have no idea how to proceed

Is there any comprehensive guide for building Scala templates. Documented to such a degree as one would find for Play! Framework?

TL;DR Where did you learn / discover how to create simple to complex Play! Scala templates?

like image 770
CybeX Avatar asked Oct 26 '25 08:10

CybeX


2 Answers

  1. Here you have pack of examples and Play seed projects: https://playframework.com/download#examples
  2. You should look for a blogposts about play templates:
    • http://mariussoutier.com/blog/2012/04/27/play-framework-2-0-templates-part-1-parameters/
  3. You should read play documentation. It isn't perfect, but very helpful. https://www.playframework.com/documentation/2.6.x/ScalaTemplates
like image 120
mgosk Avatar answered Oct 27 '25 21:10

mgosk


I would say the templates are somehow intuitive. You write html and when you want to do some scala you should start the expression with an @.

When I find myself struggling with the syntax I just google "scala play twirl map" if I want to know the syntax for the .map (twirl is the real name of the template engine)

Besides that, the documentation under https://www.playframework.com/documentation/2.6.x/ScalaTemplates should be the best resource

like image 39
pedrorijo91 Avatar answered Oct 27 '25 20:10

pedrorijo91



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!