将文字保留在摘要中 [英] Keep text in lift snippet

查看:107
本文介绍了将文字保留在摘要中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个摘录片段:

<lift:Login>
  <entry:name>
     No user logged in
  </entry:name>
</lift:Login>

我知道如果用户已登录,我可以Helpers.bind用户名,但是如何保留其中包含的以前的文本呢?当我看到scala api时,似乎不支持项目前缀元素,xhtml \\ "entry:name"只产生空Node.那我怎样才能实现这个目标呢?
万一用户登录,我想显示: User 123 在另一种情况下,我想在代码段中显示原始文本,换句话说,我只想删除对框架来说不可缺少的lift前缀标签,但它们与最终用户html无关: No user logged in

I know that I can Helpers.bind the user name if the user is logged in, but how can I preserve the former text enclosed in ? There seems to be no support to project prefixed elements when I see scala api, xhtml \\ "entry:name" yields nothing more than empty Node. So how can I accomplish such goal?
In case when the user is logged, I want to show: User 123 In the other case, I want to show the original text in snippet, in other words, I want to just remove the lift prefixed tags which are indispensable for framework, but they have nothing to do in end user html : No user logged in

推荐答案

尚不清楚您已经尝试过什么,但是在大多数情况下,不需要Scala xml转换.通常使用Helpers.bind就足够了,并且可以正确处理xml前缀. (在这方面,Scala的xml转换API有时会感觉有些不平衡.)

It’s not clear what you’ve tried already but in most cases there is no need for Scala xml transformations. Using Helpers.bind is usually sufficient and can deal with xml prefixes properly. (Scala’s xml transformations API sometimes feels a bit uneven in this respect.)

不能100%地确定要执行的操作,但这是如果登录后将用户名绑定到<entry:name/>或显示默认文本的方式.

Not 100% sure what you want to do but this is how I’d bind the user name to <entry:name/> if logged in or else show the default text.

class Login {
  def render(xhtml: NodeSeq) = bind("entry", xhtml, "name" -> name _)
  def name(in: NodeSeq) = User.currentUser.map(_.shortName).map(Text(_)) openOr in
}

添加: "name" -> name _部分意味着应使用<entry:name>标记的内容调用方法name,并且结果应替换整个标记. (我必须说,我不太确定您已经知道了关于Lift的知识;我的印象是,如果知道如何绑定User 123的人还应该知道如何绑定其他信息……)

Addition: The "name" -> name _ part means that the method name should be called with the contents of the <entry:name> tag and the result should replace the whole tag. (I must say, I’m not quite sure what you already know about lift; my impression is that if one knows how to bind User 123 one should also know how to bind other information…)

结尾的下划线是帮助此处的编译器所必需的.如果您不想转换标签的原始内容,只需绑定valdef someMethod: NodeSeq,然后在不加下划线或内联的情况下使用它们.例如. bind("entry", xhtml, "name" -> <span>Some NodeSeq</span>)

The trailing underscore is needed to help the compiler here. If you don’t want to do a transformation of the original content of the tag, you’d simply bind a val or a def someMethod: NodeSeq and then use it without underscore or even inline. E.g. bind("entry", xhtml, "name" -> <span>Some NodeSeq</span>)

这篇关于将文字保留在摘要中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆