Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using `title` with ScalaTags

The title tag is not working as expected with the ScalaTags library.

import scalatags.Text.all._

title("My Awesome Website")

How can I get this to work?

Help docs/tutorials are conveniently missing the ubiquitous title tag. I hope the dev fixes this..

https://github.com/lihaoyi/scalatags

Not Working as Expected:

If you look at how tags such as link, script, head, html are used the title tag should work the same.

For some reason the dev chose to make this tag ConcreteHtmlTag[Nothing] rather than the former tag's type ConcreteHtmlTag[String]. Its also strange that this tag is in the Tags2 package rather than Tags, it is a commonly used tag after all.

like image 228
BAR Avatar asked Mar 18 '15 15:03

BAR


2 Answers

This one seems to work:

scala> scalatags.Text.tags2.title("test")
res7: scalatags.Text.TypedTag[Nothing] = <title>test</title>

It seems like the title in scalatags.Text.all is a tag attribute (scalatags.generic.Attr) and not a TypedTag. Whether or not this is misplaced or not (or should be TypedTag[String]), I don't know. Perhaps it's just a symbol collision in your code.

An explicit import scalatags.Text.tags2.title ought to help.

like image 62
Michael Zajac Avatar answered Oct 23 '22 14:10

Michael Zajac


Instead of importing all, there are alternate imports you can use.

import scalatags.Text.short._
import scalatags.Text.tags2._

html(
  head(
    title("Your Title Here")
  ),
  body(

  )
)

More examples are in Managing Imports section in docs.

like image 35
Edward Samson Avatar answered Oct 23 '22 14:10

Edward Samson