Question

I'm changing my liferay velocity template by adding new field for structure. e.g. 'heading1' and then adding this new field to template:

<h1>Heading is: $heading1.data</h1>

But if the structure field is not yet filled the outcome is:

Heading is: $heading1.data

So I thought I can fix this by:

#if($heading1.data!="")<h1>Heading is: $heading1.data</h1>#end

But the outcome is still:

Heading is: $heading1.data

If I open the web content and just publish it then the outcome is right, it doesn't show anything, but I don't want do find every similar web content and start publish them manually.

So is there a way how to check if the heading is just not filled?

Thanks.

Was it helpful?

Solution

You can use a silent reference to tell Velocity not to display an empty reference:

<h1>Heading is: $!heading1.data</h1>

or you can directly test whether its content does exist:

#if($headings1.data) <h1>Heading is: $heading1.data</h1> #end

Up to Velocity 1.7, this test will be false if the reference is null or uninitialized, but will still be true if the reference contains an empty string. Empty strings will also evaluate to false in next versions.

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