为什么这个html不是由scala打印的?

时间:2013-12-03 00:24:52

标签: playframework playframework-2.0

我正在尝试使用Play Framework创建站点地图。为此我需要一个while循环,它会一直运行,直到达到一个特定的Long值。循环实际上有效但内部的html没有打印,尽管println()工作正常(输出打印在控制台上)

    @{
    var i = 0L
    var amountOfSitemaps = 10L;
    while(i < amountOfSitemaps) {
        <url>
            <loc>http://www.example.com/</loc>
            <lastmod>2005-01-01</lastmod>
            <changefreq>monthly</changefreq>
            <priority>0.8</priority>
        </url>
        println("why is the stuff above not printed?!")
        i+=1
    }}

感谢您的任何建议!

1 个答案:

答案 0 :(得分:1)

您最近的样本解决方案是:

@for(item <- 0 until 10) {
    <url>
        <loc>http://www.example.com/</loc>
        <lastmod>2005-01-01</lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
}

在真实的站点地图中,它将类似于:

@(listOfSites: List[Site])

@for(site <- listOfSites) {
    <url>
        <loc>@site.url</loc>
        <lastmod>@site.lastMod</lastmod>
        <changefreq>@site.changeFreq</changefreq>
        <priority>@site.priority</priority>
    </url>
}

假设您传递了

检查@for(item <- 0 until 10)@for(item <- 0 to 10)

之间的区别