Crayl
Crayl

Reputation: 1911

Why is this html isn't printed by scala?

I'am trying to create a sitemap with Play Framework. For that I need a while loop which runs till a specfic Long value is reached. The loop actually works but the html inside isn't printed altough the println() works fine (output is printed on the console)

    @{
    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
    }}

Thanks for any suggestions!

Upvotes: 0

Views: 43

Answers (1)

biesior
biesior

Reputation: 55798

The nearest solution for your sample is:

@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>
}

In real sitemap it would be something like:

@(listOfSites: List[Site])

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

Assuming that you pass a

check the difference between @for(item <- 0 until 10) and @for(item <- 0 to 10)

Upvotes: 1

Related Questions