[
https://issues.apache.org/jira/browse/FREEMARKER-20?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ondra Žižka updated FREEMARKER-20:
----------------------------------
Description:
I'd like to be able to generate a NEW LINE conditionally, with 1 line of
template source code.
{code}
<#if
dep.classifier??><classifier>${dep.classifier}</classifier></#if>
{code}
I haven't found a way. {{#t}} and {{#rt}} and {{#lt}} apply at compile time, so
they don't care about the condition. So they strip even if the content is
there, which I don't want.
I could do this:
{code}
<#if dep.classifier??>${"
"}<classifier>${dep.classifier}</classifier>${"\n"}</#if><#t>
{code}
So that's the request. It can also be anything what helps me achieve that.
Until then, I have to do:
{code}
<#if dep.classifier??>
<classifier>${dep.classifier}</classifier>
</#if>
{code}
Which I don't like because it makes the templates way longer.
Or
{code}
<#if dep.classifier??><classifier>${dep.classifier}</classifier>
</#if><#if
dep.classifier??><classifier>${dep.classifier}</classifier>
</#if>
...
{code}
Which I don't like because it's messy.
Or
{code}
<#if dep.classifier??>${"
"}<classifier>${dep.classifier}</classifier>${"\n"}</#if><#t>
{code}
Which I don't like because it adds superfluous pieces to the template.
was:
I'd like to be able to generate a line conditionally, with 1 line of template
source code.
{code}
<#if
dep.classifier??><classifier>${dep.classifier}</classifier></#if>
{code}
I haven't found a way. {{#t}} and {{#rt}} and {{#lt}} apply at compile time, so
they don't care about the condition. So they strip even if the content is
there, which I don't want.
I could do this:
{code}
<#if dep.classifier??>${"
"}<classifier>${dep.classifier}</classifier>${"\n"}</#if><#t>
{code}
So that's the request. It can also be anything what helps me achieve that.
Until then, I have to do:
{code}
<#if dep.classifier??>
<classifier>${dep.classifier}</classifier>
</#if>
{code}
Which I don't like because it makes the templates way longer.
Or
{code}
<#if dep.classifier??><classifier>${dep.classifier}</classifier>
</#if><#if
dep.classifier??><classifier>${dep.classifier}</classifier>
</#if>
...
{code}
Which I don't like because it's messy.
Or
{code}
<#if dep.classifier??>${"
"}<classifier>${dep.classifier}</classifier>${"\n"}</#if><#t>
{code}
Which I don't like because it adds superfluous pieces to the template.
> Some single-line solution to avoid empty lines
> -----------------------------------------------
>
> Key: FREEMARKER-20
> URL: https://issues.apache.org/jira/browse/FREEMARKER-20
> Project: Apache Freemarker
> Issue Type: New Feature
> Components: engine
> Affects Versions: 2.3.23
> Reporter: Ondra Žižka
>
> I'd like to be able to generate a NEW LINE conditionally, with 1 line of
> template source code.
> {code}
> <#if
> dep.classifier??><classifier>${dep.classifier}</classifier></#if>
> {code}
> I haven't found a way. {{#t}} and {{#rt}} and {{#lt}} apply at compile time,
> so they don't care about the condition. So they strip even if the content is
> there, which I don't want.
> I could do this:
> {code}
> <#if dep.classifier??>${"
> "}<classifier>${dep.classifier}</classifier>${"\n"}</#if><#t>
> {code}
> So that's the request. It can also be anything what helps me achieve that.
> Until then, I have to do:
> {code}
> <#if dep.classifier??>
> <classifier>${dep.classifier}</classifier>
> </#if>
> {code}
> Which I don't like because it makes the templates way longer.
> Or
> {code}
> <#if dep.classifier??><classifier>${dep.classifier}</classifier>
> </#if><#if
> dep.classifier??><classifier>${dep.classifier}</classifier>
> </#if>
> ...
> {code}
> Which I don't like because it's messy.
> Or
> {code}
> <#if dep.classifier??>${"
> "}<classifier>${dep.classifier}</classifier>${"\n"}</#if><#t>
> {code}
> Which I don't like because it adds superfluous pieces to the template.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)