Play framework dynamic template include

sparkr

I have a template that has to include another template based on the file name that comes from the database. For example, here is a template that takes a String that contains the name of the template file that will be included in another template.

@(sourceCodeFileName: Option[String])
@{sourceCodeFileName match {
    case Some(sourceCode) => {
        @sourcecode.sourceCodeFileName + "scala.html"
    }
}}

Where sourcecode is the package where the actual template resides. For example., if the String parameter to the above template is given as myview, then I want to include myview.scala.html. Is there a way to do this in Play framework?

tomekwi

To inject HTML from a static file to a scala template, you can define a function in your template:

@import scala.io.Source

@injectHtmlFromFile(sourceCodeFilename: String) = { @{
    Html(Source.fromFile("static/html/" + sourceCodeFilename + ".html").mkString)
}}

…and call it later in the template this way:

@injectHtmlFromFile(sourceCode.sourceCodeFileName)
Side note

I'm not sure I quite understand the question – I've answered the OP's comment and the same question posted by him on Google Groups.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Play framework dynamic template include

From Dev

Display Dynamic Image in Play! Framework Template

From Dev

Play Framework Scala Template

From Dev

Dynamic include template angular directive

From Dev

Scala Play Framework - Dynamic Forms

From Dev

Update parent template's dynamic template include from child template

From Dev

How to include file in production mode for Play framework

From Dev

Include module from Nexus in Play Framework 1.2

From Dev

Meteor JS: include dynamic name template in layout

From Dev

Bounded generic parameters in Play Framework template

From Dev

How to inject Application in Play Framework 2.5 template

From Dev

Play Framework template that is actually a JS file

From Dev

Get scala template in a variable in Play Framework

From Dev

play framework passing sub class to scala template

From Dev

Play Framework template, iterate backwards over List

From Dev

using bootstrap with play framework scala template

From Dev

Play2 Framework Float Format in Template

From Dev

Play framework scala template with case statement on enumeration

From Dev

Get Javascript variable in Template play framework 1.2.6

From Dev

play framework passing sub class to scala template

From Dev

using bootstrap with play framework scala template

From Dev

Referencing template syntax system in Play framework

From Dev

Play! Framework - return multiple list to template

From Dev

Microservices template project for Play Framework with java

From Dev

Purely Dynamic forms using play framework

From Dev

Long dynamic routes in play framework 2

From Dev

Play Framework - Register a custom DataBinder for dynamic fields

From Dev

Dynamic value of textarea with Play framework with Silhouette

From Dev

Play Framework, Dynamic statement inside for loop

Related Related

  1. 1

    Play framework dynamic template include

  2. 2

    Display Dynamic Image in Play! Framework Template

  3. 3

    Play Framework Scala Template

  4. 4

    Dynamic include template angular directive

  5. 5

    Scala Play Framework - Dynamic Forms

  6. 6

    Update parent template's dynamic template include from child template

  7. 7

    How to include file in production mode for Play framework

  8. 8

    Include module from Nexus in Play Framework 1.2

  9. 9

    Meteor JS: include dynamic name template in layout

  10. 10

    Bounded generic parameters in Play Framework template

  11. 11

    How to inject Application in Play Framework 2.5 template

  12. 12

    Play Framework template that is actually a JS file

  13. 13

    Get scala template in a variable in Play Framework

  14. 14

    play framework passing sub class to scala template

  15. 15

    Play Framework template, iterate backwards over List

  16. 16

    using bootstrap with play framework scala template

  17. 17

    Play2 Framework Float Format in Template

  18. 18

    Play framework scala template with case statement on enumeration

  19. 19

    Get Javascript variable in Template play framework 1.2.6

  20. 20

    play framework passing sub class to scala template

  21. 21

    using bootstrap with play framework scala template

  22. 22

    Referencing template syntax system in Play framework

  23. 23

    Play! Framework - return multiple list to template

  24. 24

    Microservices template project for Play Framework with java

  25. 25

    Purely Dynamic forms using play framework

  26. 26

    Long dynamic routes in play framework 2

  27. 27

    Play Framework - Register a custom DataBinder for dynamic fields

  28. 28

    Dynamic value of textarea with Play framework with Silhouette

  29. 29

    Play Framework, Dynamic statement inside for loop

HotTag

Archive