Search code examples
liferay-6velocityliferay-theme

Liferay Theme, show component only in welcome page


I'm editing a Liferay Theme. By editing the portal_normal.vm, I want to conditionally show or hide a component

#if ($is_welcome_page)
<span class="lang">
    $taglibLiferay.language("fm",null,"languageId",1)
    <br>
    <div class="my-menu">
       ...... lots of irrelevant stuff here
    </div>              
</span>
#end>

How can I make that $is_welcome_page variable become true only if the current page is the Portal's Welcome page ? I guess I could get the friendly Url and check it, but I'm not sure how I can do that. Any working code would be much appreciated!

Edit: using Liferay 6.1.0 if that helps


Solution

  • Generally customising themes per-page is a bad practice (theme should be global or customized for a specific site). To do it correctly, you should just add language portlet on your main site instead of hardcoding it within a theme template.

    Anyway, if you really want to do it, you have access to the layout object (directly or via $layout = $theme.getLayout()), which in Liferay is a representation of a page (for example it has getFriendlyURL() method). Check Liferay Wiki for the list of all variables accessible from Velocity, there are lots of others properties you could use, for example the_title.

    This is a theme customization, so a good practice is to put all custom settings within Theme Settings. You can read how to do it in Liferay's documentation.