Tech Tip: Creating a case statement with 4D Tags
PRODUCT: 4D | VERSION: 13.0 | PLATFORM: Mac & Win
Published On: May 6, 2012
4D v13 has a new 4D HTML Tag called #4DELSEIF. This can be used to create a case statement in HTML pages. Without the #4DELSEIF tag this could only being done using a series of nested #4DIF tags. For example the following two sets of HTML code, one using nested #4DIF tags and one using #4DELSEIF have identical results.
<!--#4DIF LoggedIn=False--> <!--User is not logged in, display login page--> <!--#4DINCLUDE Login.htm --> <!--#4DELSE--> <!--#4DIF User="Admin"--> <!--Admin logged in, display admin page--> <!--#4DINCLUDE AdminPanel.htm --> <!--#4DELSE--> <!--#4DIF User="Manager"--> <!--Manager logged in, display manager page--> <!--#4DINCLUDE SalesDashboard.htm --> <!--#4DELSE--> <!--Other user logged in, display generic page--> <!--#4DINCLUDE ItemList.htm --> <!--#4DENDIF--> <!--#4DENDIF--> <!--#4DENDIF--> |
<!--#4DIF LoggedIn=False--> <!--User is not logged in, display login page--> <!--#4DINCLUDE Login.htm --> <!--#4DELSEIF User="Admin" --> <!--Admin logged in, display admin page--> <!--#4DINCLUDE AdminPanel.htm --> <!--#4DELSEIF User="Manager" --> <!--Manager logged in, display manager page--> <!--#4DINCLUDE SalesDashboard.htm --> <!--#4DELSE--> <!--Other user logged in, display generic page--> <!--#4DINCLUDE ItemList.htm --> <!--#4DENDIF--> |
The second example has better readability and will be much easier to modify than the first.