3

As the tittle says... How to know if a page is private or public? I need to implement some logic in a velocity file from my custom theme only for private pages.

I found this page Access Objects from Velocity and it seems very useful but I need some help with the API because I don't know which utility class has a method for what I'm looking.

I thought in a workaround making my condition a theme property, but I don't want to depend from the admin user

Thank you

3 Answers3

8

Artem Khojoyan's answer above is to the point.

But I would like to add some more info.

Page in liferay is represented by Layout object. Theme template supports layout as well as many more objects in the theme-template, which you can check in the class VelocityVariablesImpl. You can check statements like velocityContext.put("key","value"); where key is the variable you can use in velocity template as $key.

So since $layout is nothing but the Layout object, you can use all the public instance methods of this Layout object in velocity.

For every request, $layout in theme represents the current-page, which needs to be loaded.

So finally you can do the following in your portal_normal.vm or init_custom.vm or any other *.vm you have in the theme:

#if($layout.isPublicLayout())
  #*.. do something if it is public ...*#
#else
  #*.. do something if it is private ...*#
#end

Hope this helps.

Community
  • 1
  • 1
Prakash K
  • 11,669
  • 6
  • 51
  • 109
3
#if($layout.isPublicLayout())
  //
#else
  //
#end
Artem Khojoyan
  • 857
  • 1
  • 6
  • 11
0

you can use as well :

#if($layout.isPublicLayout())
  #*.. This is public ...*#
#elseif ($layoutmodel.isprivatelayout())
  #*.. This is private ...*#
#end

for more details about other methodes for Liferay Interface Layout

Seif Tml
  • 2,413
  • 1
  • 17
  • 15