Is there a shorthand way to check if a string is null or empty in template syntax?
Currently I have to do this:
<<if [item.Text != null && item.Text != “”]>>
Is it possible to do something like:
<<if [!String.IsNullOrWhiteSpace(item.Text)]>>
or
<<if [item.Text?.Any()]>>
I know the above examples don’t work, but is there something similar that may be used?
1 Like
We are investigating this scenario. Your investigation ticket ID is ASSEMBLYNET-155. As there’s any update, you’ll be notified.
We investigated this scenario and below is our feedback.
All of the options you are working with are appropriate with small modifications of the template or source code. Below is the source code we used:
Item item = new Item { Text = "not empty" };
DocumentAssembler assembler = new DocumentAssembler();
// The following line is needed solely for Option 2 in the template to work.
// It is not needed for the other options and can be removed if using only Option 1 or 3.
assembler.KnownTypes.Add(typeof(String));
assembler.AssembleDocument(@"Test155.docx", @"Test155 Out.docx", new DataSourceInfo(item, "item"));
and
public class Item
{
public string Text { get; set; }
}
The template document is attached Test155.zip (10.0 KB).