SharpDocx icon indicating copy to clipboard operation
SharpDocx copied to clipboard

if statement deletes the entire paragraph

Open tugrulelmas opened this issue 5 years ago • 1 comments

Hi,

I want to add a sentence to end of the paragraph with the following code, but when the statement is false the entire paragraph is deleted and the result is empty. If the statement is true there is no problem. Everything works as expected.

This is a paragraph. <% if (false) { %> The entire paragraph will be deleted. <% } %>

If I to do so with the Write method there is no problem, but in this case I am losing the formatting option.

This is a paragraph. <% if (false) { Write("This won't be displayed."); } %>

tugrulelmas avatar May 18 '20 19:05 tugrulelmas

You can’t use text blocks to conditionally display a part of a paragraph. It’s all or nothing. This makes the text block implementation much simpler. It's not very likely that this will change soon. However, it might also give some unexpected results, as you did notice.

I added a section 'Text block limitations' to the Tutorial, where this issue is explicitly mentioned.

egonl avatar May 27 '20 22:05 egonl