The following code examples demonstrate how to call the PushIndent method from a text template. Paste these code examples into any text template file and run the text template transformation to see the results.
This example calls the PushIndent method and adds four spaces as the indent. Notice that the indentation of the WriteLine statements in the code does not affect the indentation of the output.
<#
PushIndent(" ");
WriteLine("Hello");
WriteLine("How are you?");
WriteLine("Goodbye");
ClearIndent();
#>
<#
PushIndent(" ")
WriteLine("Hello")
WriteLine("How are you?")
WriteLine("Goodbye")
ClearIndent()
#>
This example produces the following output:
Hello
How are you?
Goodbye
The following example calls the PushIndent method multiple times. The first time it adds four spaces as the indent, the second time it adds an additional four spaces as the indent.
<#
PushIndent(" ");
WriteLine("Hello");
WriteLine("How are you?");
PushIndent(" ");
WriteLine("I am fine, thank you. How are you?");
PopIndent();
WriteLine("I am fine too, thank you.");
WriteLine("Goodbye");
PushIndent(" ");
WriteLine("Goodbye");
ClearIndent();
#>
<#
PushIndent(" ")
WriteLine("Hello")
WriteLine("How are you?")
PushIndent(" ")
WriteLine("I am fine, thank you. How are you?")
PopIndent()
WriteLine("I am fine too, thank you.")
WriteLine("Goodbye")
PushIndent(" ")
WriteLine("Goodbye")
ClearIndent()
#>
This example produces the following output:
Hello
How are you?
I am fine, thank you. How are you?
I am fine too, thank you.
Goodbye
Goodbye
The following example calls the PushIndent method and includes words in the indent text.
<#
WriteLine("The first five numbers:");
PushIndent(" Number: ");
for(int i=1; i<6; i++)
{
WriteLine(i.ToString());
}
ClearIndent();
#>
<#
WriteLine("The first five numbers:")
PushIndent(" Number: ")
For i as integer = 1 To 5
WriteLine(i.ToString())
Next
ClearIndent()
#>
This example produces the following output:
The first five numbers:
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5