为什么速度(Velocity)不能正确显示应该以 “display: flex;” 显示的
元素?

huangapple 未分类评论51阅读模式
英文:

Why isn't Velocity displaying <div>'s that should be displayed as "display: flex;" correctly?

问题

我在使用Apache Velocity引擎时遇到了问题。

我在模板中有一段HTML代码:

  1. &lt;p&gt;
  2. &lt;span&gt;&lt;b&gt;${contextString}:${context.contextTitle}&lt;/b&gt;&lt;/span&gt;
  3. &lt;div style=&quot;displayflex;&quot;&gt;
  4. &lt;div&gt;${published}&lt;/div&gt;
  5. &lt;div&gt;${context.published}&lt;/div&gt;
  6. &lt;div&gt;${noWorkflow}&lt;/div&gt;
  7. &lt;div&gt;${context.reviewed}&lt;/div&gt;
  8. &lt;/div&gt;
  9. &lt;/p&gt;

但是当我测试这个模板时,Velocity似乎会将这些DIV转换为常规的display:block;,或者完全忽略display:flex;,导致所有项目都显示在新行中。

为什么Velocity会显示出现这种错误?有没有方法可以修复这个问题?

英文:

I have problem with Apache Velocity engine.

I have a piece of html in my template:

  1. &lt;p&gt;
  2. &lt;span&gt;&lt;b&gt;${contextString}: ${context.contextTitle}&lt;/b&gt;&lt;/span&gt;
  3. &lt;div style=&quot;display: flex;&quot;&gt;
  4. &lt;div&gt;${published}&lt;/div&gt;
  5. &lt;div&gt;${context.published}&lt;/div&gt;
  6. &lt;div&gt;${noWorkflow}&lt;/div&gt;
  7. &lt;div&gt;${context.reviewed}&lt;/div&gt;
  8. &lt;/div&gt;
  9. &lt;/p&gt;

But when I test this template, Velocity seems to somehow convert those DIVs into regular display: block; or is ignoring display: flex; completely, displaying all items in new lines.

Why is Velocity displaying this incorrectly? Is there any way to fix this?

答案1

得分: 0

这并不是一个 Velocity 的问题:在 $references#directives 之外,Velocity 不会解释要格式化的文本,无论是 HTML 还是其他内容。

在你的代码中至少存在一个可能引起问题的 HTML 问题:&lt;p&gt; 标签不能包含 &lt;div&gt; 标签,所以当它遇到第一个 &lt;div&gt; 标签时,&lt;p&gt; 标签会被关闭。请参考这个相关答案

英文:

This is not a Velocity problem: outside of $references and #directives, Velocity does not interpret the text it is formatting, would it be HTML or else.

There is at least one HTML problem in your code that may cause this: &lt;p&gt; tags cannot contain &lt;div&gt; tags, so the &lt;p&gt; is closed when it encounters the first &lt;div&gt;. See this related answer.

huangapple
  • 本文由 发表于 2020年4月6日 21:53:52
  • 转载请务必保留本文链接:https://java.coder-hub.com/61061436.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定