Lift Framework BindHelpers.attr Question (or better practice?)

My problem is extracting xhtml attributes to generate absolute links, since they need to be different on testing and production environment. I would like to use a "global snippet" that binds all "src" and "href" attributes to "localhost:8080" or "www.mydomain.com" depending on a conf value.

This is how the template looks like:

<lift:Global>
  <html><body><a G:href="/somelink">some text</a></body></html>
</lift:Global>

And this is the Global.render method:

bind("G",template,
  AttrBindParam("href",Conf.localhost
    +BindHelpers.attr("G","href").map(_.toString).getOrElse("none") ,"href")
)

But in the rendered page all I see is ... href="confValueNone".

What am I doing wrong? Is there a better way to configure for different environments?

1
задан Jasper 27 August 2010 в 09:48
поделиться

1 ответ

Теперь я использую AttributeSnippets. Они немного тяжелее на стороне шаблона, но в результате получаются более чистые фрагменты.

фрагмент:

import xml.{UnprefixedAttribute, MetaData}

...

def src(in:MetaData):MetaData = {
  new UnprefixedAttribute("src",Conf.localhost+in.value.toString,scala.xml.Null)
}

def href(in:MetaData):MetaData = {
  val out = new UnprefixedAttribute("href",Conf.localhost+in.value.toString,scala.xml.Null)
  out
}

шаблон:

...
<script type="text/javascript" lift:Global.src="/inc/showdown.js" />
<link rel="stylesheet" type="text/css" lift:Global.href="/inc/style.css" />
...
2
ответ дан 2 September 2019 в 21:48
поделиться
Другие вопросы по тегам:

Похожие вопросы: