Question

I'm new to FreeMarker and I'm struggling with some code rendering... It'll be great if I could have any hint on what's happening. Basically, what I'm doing is iterating information coming from a CMS and building CSS rules to define the background of an element. The code I'm using is:

<style type="text/css">
    <#list backgroundTest as backgroundTestRule>
        <#if backgroundTestRule.elementID?? && backgroundTestRule.elementID != "">
            <#assign selectorID = backgroundTestRule.elementID?lower_case?replace("[^a-z0-9\\[\\]]", "", "ri")>
        <#else>
            <#assign selectorID = "">
        </#if>
        .foo${"#${selectorID}"} {
            background: url(${selectorID.backgroundImage.url}) no-repeat;
        }
    </#list>
</style>

And when I inspect the code, I'm getting this:

    .foo#selectorid {
        background: url(foo.jpg
) no-repeat;
    }

The code works only if I don't use "" on the background URL (background: url("foo.jpg")), and I suppose it's because it's adding a line break before the parenthesis is closed. I tried to use some options I took from here: http://freemarker.org/docs/dgui_misc_whitespace.html and here: http://freemarker.org/docs/ref_directive_t.html, but nothing worked (<#compress>, <#t>, etc.).

Thanks, greetings!

Was it helpful?

Solution

Try this:

background: url(${selectorID.backgroundImage.url?chop_linebreak}) no-repeat;

it looks like the selectorID.backgroundImage.url parameter has a line break at the end.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top