开发者

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?


I use AttributeSnippets now. They are a bit heavier on the template side, but result in cleaner snippets.

snippet:

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
}

template:

...
<script type="text/javascript" lift:Global.src="/inc/showdown.js" />
<link rel="stylesheet" type="text/css" lift:Global.href="/inc/style.css" />
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜