使用 <wicket:message>生成部分格式化文本的标签 [英] Using <wicket:message> tag to produce partially formatted text

查看:30
本文介绍了使用 <wicket:message>生成部分格式化文本的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过 wicket:message 这里,但似乎无法让它做我想做的一切.

I've read about wicket:message here, but can't seem to make it do everything I'd like.

假设我有一个带有 <wicket:message key="text"/> 的 HTML 页面和一个包含 text=Blah blah: important point, foo bar 的属性文件代码>.我想知道如何将文本的 part 设为粗体(或对其应用任意 CSS),以实现如下输出:

Say I have a HTML page with <wicket:message key="text"/> and a properties file containing text=Blah blah: important point, foo bar. I'm wondering how to make part of the text bold (or apply arbitrary CSS to it), to achieve output like:

废话废话:重点,foo bar

Blah blah: important point, foo bar

请注意,这些实际上都不是动态,所以如果可以避免的话,我不想用 Java 做任何事情.

Note that none of this is actually dynamic, so I wouldn't want to do anything in Java, if that can be avoided.

我尝试过使用类似以下内容的嵌套标签,但没有成功.

I've tried nesting tags with something like the following, but no luck.

<wicket:message key="text">
    <span class="bold"><wicket:message key="text2"/></span>
</wicket:message>

text=Blah blah: ${text2}, foo bar
text2=important point

这在 Wicket 中是否可行,而无需 1) 从 Java 端注入格式化部分或 2) 仅将文本拆分为(在本例中)三个不同的属性?

Is this even possible in Wicket without 1) injecting the formatted part from Java side or 2) just splitting the text into (in this case) three different properties?

推荐答案

最简单的方法是将标签放在本地化文件中:

The easiest way is to put the tags inside your localization file:

text=废话:<strong>text2</strong>, foo bar

text=Blah blah: <strong>text2</strong>, foo bar

您也可以稍后使用标签和资源模型来替换它:

You could also use a Label and a ResourceModel to replace it later:

text=废话:[b]text2[/b], foo bar

text=Blah blah: [b]text2[/b], foo bar

在你的模型中 getObject() 或在你的标签中:

And in your model getObject(), or in your Label:

string.replace("[b]", "");
string.replace("[/b]", "</strong>");

string.replace("[b]", "<strong>");
string.replace("[/b]", "</strong>");

或者,更好的是,尝试在您的标签中重用 Markdown 实现.

Or, even better, try to reuse a Markdown implementation in your Label.

这篇关于使用 &lt;wicket:message&gt;生成部分格式化文本的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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