Using `title` with ScalaTags

The header tag does not work as expected with the ScalaTags library.

import scalatags.Text.all._ title("My Awesome Website") 

How can I make this work?

In reference documents / tutorials, it’s convenient to skip the ubiquitous title tag. I hope the developer fix this.

https://github.com/lihaoyi/scalatags

Doesn't work as expected:

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

For some reason, the developer decided to make this ConcreteHtmlTag[Nothing] tag, rather than the old ConcreteHtmlTag[String] tag type. It’s also strange that this tag is in the Tags2 package, not Tags , it is a commonly used tag.

+5
source share
2 answers

This seems to work:

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

It appears that title in scalatags.Text.all is an attribute of the tag ( scalatags.generic.Attr ), not TypedTag . Whether this is inappropriate or not (or should be TypedTag[String] ), I do not know. Perhaps this is just a collision of characters in your code.

Explicit import scalatags.Text.tags2.title should help.

+7
source

Instead of importing all you can use alternative imports.

 import scalatags.Text.short._ import scalatags.Text.tags2._ html( head( title("Your Title Here") ), body( ) ) 

For more examples, see Managing Import Settings in Documents.

+1
source

Source: https://habr.com/ru/post/1215604/


All Articles