1

I wish to place markers in the output of HTML (only during development) such that I know exactly which templates and snippets are being called at any given time. (It's huge and growing library...)

Currently I have something like this:

@if(tkAuthenticatedRequest.isDev) {<!-- mystuff.myform.helpers.snippet.scala.html -->}

This works of course but is prone to error or omission.

Can we detect the actual filename and have it bleed thru automatically?

Is there perhaps a better way to attach this to dev and not need the authentication at all? While I've lazy val'ed the isDev call so it only has a single hit nonetheless I'm open to better ideas.

2
  • Maybe you can use something like @this.getClass().getName(), but I don't know what it will return in a template file... Aug 28, 2015 at 8:42
  • That my friends almost kinda works! It gives the "view" name of the template. E.g. the name you would use to call it in a template. It doesn't seem to take into account any submodule paths etc...
    – Techmag
    Aug 29, 2015 at 21:55

1 Answer 1

1

The magic answer if you want the actual file name is as follows:

@if(tkAuthenticatedRequest.isDev) { 
  <!-- @Option(this.getClass().getProtectionDomain().getCodeSource()).map(x => x.getLocation()) --> 
}

Note that Twirl has a hard time digesting this unless it is split into three lines so you might want to make a Util function out of it and just pass this.getClass() to that function.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.