为什么这不将多个HTML参数传递给模板 [英] Why doesn't this pass multiple HTML parameters to template

查看:115
本文介绍了为什么这不将多个HTML参数传递给模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解,但答案非常奇怪,无论如何,我都想了解为什么这种特定方法行不通:

I know about this and this, but the answers are very strange, and in any case, I am looking to understand why this particular approach does not work:

@myPackage.views.html.ol(
  {
    Hello
  }, {
    World
  }
)

myPackage.views.html.ol.scala.html

@(ol:Html*)

<ol>
  @for(li <- ol) {
    <li>
      (hi)
      <span class="li-body">@li</span>
    </li>  
  }
</ol>

错误:

not found: value Hello

我必须对模板引擎的规则缺乏基本的了解,因为从直觉上看,这对我来说是正确的.

I must lack fundamental understanding about the rules of the template engine, because this seems intuitively correct to me.

推荐答案

@字符标记动态语句的开始,因此您不再使用模板语法.它试图将ol()函数的参数解释为直接的Scala/Java代码,而不是模板语法.

The @ character marks the beginning of a dynamic statement, so you are no longer in template syntax. It's trying to interpret the arguments to the ol() function as straight Scala/Java code, not the template syntax.

这取决于您要尝试执行的操作,但是有两种方法可以执行此操作.您可能还可以使用@defining帮助器.

It depends on what exactly you're trying to do, but here are two ways to do it. You could probably also use the @defining helper.

@myPackage.views.html.ol(Html("Hello"), Html("World"))

另一种方法是在视图的开头定义Html块.

Another way is to define the Html blocks at the beginning of your view.

@html1 = { Hello }
@html2 = { <strong>World</strong> }

@main(){
  @myPackage.views.html.ol(html1, html2)
}

这篇关于为什么这不将多个HTML参数传递给模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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