Search code examples
if-statementtapestrytml

How can I make the "if" statement for a link to work fine if I want to show it only if it's not the "Index" page


In my application,the first page is Index.tml and I have a login form. The layout for this application has a menu with some links in it and I added another one which is called "Delogheza-te"=Log-out. What I want is that ,the "log-out link" to be visible only after the user logged-in. The log-out link should be visible on all pages except "Index.tml". How can I do that? I tryed this but it's wrong.

<t:if  t:page!="Index">
 <a href="#" t:type="PageLink" t:page="Index">Delogheaza-te</a>
 </t:if>

Solution

  • For this situation I like to give the layout component a component parameter, maybe a boolean showLogout, which is true by default but can be set to false in some pages such as the index page.

    -- in Layout.java --

    @Parameter(value="true")
    @Property
    boolean showLogout;
    

    -- in Layout.tml --

    <t:if test="showLogout">
         (logout link here)
    </t:if>
    

    -- in Index.tml --

    <html t:type="layout" showLogout="false">