Fórum

No $themeDisplay accessable in new Velocity Template

jeff gerbracht, modificado 15 Anos atrás.

No $themeDisplay accessable in new Velocity Template

Junior Member Postagens: 65 Data de Entrada: 05/06/08 Postagens Recentes
I've created a new Velocity template and attached it to a new structure which I also created based on BASIC-ARTICLE. I'm trying to access the $themeDisplay and $user but these don't seem to exist in the velocity context for the template. I've searched the forums and the wiki to no avail. The page which contains the article using the new template and structure is set to the Classic theme.

#set ($user_greeting_now = $user.getGreeting())
$user_greeting_now
theme=$themeDisplay


The page displays

$user_greeting_now theme=$themeDisplay

addendum:
I've created the template using the journal portlet, not by adding the template to WebContent/html/themes/classic/templates

I'm running 5.1.1 on Websphere 7

Any help appreciated,
Thanks,
Jeff
thumbnail
Ray Augé, modificado 15 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Legend Postagens: 1197 Data de Entrada: 08/02/05 Postagens Recentes
Sorry Jeff,

[tt]$themeDisplay[/tt] and [tt]$user[/tt] are not available in the Journal VM context...

BUT, all is not lost.

You have access to $request (which is not a "real" http request, but rather a HashMap mockup with all the important "but safe" information from the request).

ALSO, $request contains a subset of the details in the real $themeDisplay.

So, to get the current user you would have to make sure that you have access to "serviceLocator" tool in VM templates.

    #
    # Input a comma delimited list of variables which are restricted from the
    # context in Velocity based Journal templates.
    #
    #journal.template.velocity.restricted.variables=serviceLocator
    journal.template.velocity.restricted.variables=


Then in your template do:

#set ($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set ($user = $userLocalService.getUserById($getterUtil.getLong($request.remote-user)))
#set ($user_greeting_now = $user.getGreeting())


I'm not sure what you need from $themeDisplay, but let me know and I'll let you know if it's possible.
jeff gerbracht, modificado 15 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Junior Member Postagens: 65 Data de Entrada: 05/06/08 Postagens Recentes
Ray,
Thanks for clarifying what's available to the journal vm context, the wiki page implies that everything that available in a normal template is also available in the journal template. I've printed out the request so now can see what's available.
Thanks for your help.
Jeff
jeff gerbracht, modificado 15 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Junior Member Postagens: 65 Data de Entrada: 05/06/08 Postagens Recentes
I've updated the wiki page for Journal Template/Velocity to more accurately reflect what variables are available in the velocity context.
nidhi singh, modificado 15 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Junior Member Postagens: 57 Data de Entrada: 29/10/08 Postagens Recentes
hi

I want to know there is any velocity variable for user Role, i have to use in Journal content.

please help me
jeff gerbracht, modificado 15 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Junior Member Postagens: 65 Data de Entrada: 05/06/08 Postagens Recentes
You have access to RolePermissions in Velocity (see the wiki page on velocity templates. Also you can access several differnet localservices, in com.liferay.portlet.journal.service and com.liferay.portal.service.* which has a RoleLocalService

#set ($roleLocalService =$serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
Marc Piparo, modificado 12 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Junior Member Postagens: 43 Data de Entrada: 14/03/11 Postagens Recentes
HI All.
Informative thread. thanks.
Any idea though why my getUserRoles call is returning me an empty list?

#set ($user_id = $request.theme-display.user-id)
#set ($roles = $serviceLocator.findService("com.liferay.portal.service.RoleService").getUserRoles($getterUtil.getLong(user_id)))
user_id=$user_id
roles=$roles

output:
user_id=10612 roles=[]

trying to check if user is a guest user role or not, but list returns empty.
any ideas?

thanks!
thumbnail
Thiago Leão Moreira, modificado 12 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Legend Postagens: 1449 Data de Entrada: 10/10/07 Postagens Recentes
I think you are missing the $ at $getterUtil.getLong($user_id)
thumbnail
Samir Gami, modificado 12 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Regular Member Postagens: 162 Data de Entrada: 04/02/11 Postagens Recentes
I think, class should be "com.liferay.portal.service.RoleLocalService", And "($getterUtil.getLong($user_id)))"
thumbnail
Auditya manikanta Vadrevu, modificado 14 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Master Postagens: 621 Data de Entrada: 06/05/08 Postagens Recentes
hi ray auge,

iam using 5.1.1 version. i want to access the user details from journal template.

for that first i have added this in portal-ext.properties

journal.template.velocity.restricted.variables=serviceLocator


then from template i have tried with this,

1.
#set ($userId = $getterUtil.getLong($request.remote-user))
##set($userLocalService =$serviceLocator.findExceptionSafeService("com.liferay.portal.service.UserLocalService"))
##set($user = $userLocalService.getUserById($userId))


and also with
2.
#set ($userId = $getterUtil.getLong($request.remote-user))
#set ($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set($user = $userLocalService.getUserById($userId))


in both codes only userId working. iam not able to get ${user} value. Is any thing i need to add to this...

Thanks in Advance,
V.Auditya
thumbnail
Amos Fong, modificado 14 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
Hey Auditya,

This property is actually a list of restricted variables. So you want to add this to portal-ext.properties:

journal.template.velocity.restricted.variables=
thumbnail
Auditya manikanta Vadrevu, modificado 14 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Master Postagens: 621 Data de Entrada: 06/05/08 Postagens Recentes
hi amos,

thanks it worked.

Adding this property causes any security threat. ?

Can all the user details can be updated,deleted ( or adding new user) from journal content ?


With Regards,
V.Auditya
thumbnail
Amos Fong, modificado 14 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
Adding this property causes any security threat. ?


Possibly, depending if you trust the people who can create templates. You should probably limit who can create journal articles/templates.

Can all the user details can be updated,deleted ( or adding new user) from journal content ?


Yes, you can call userlocalservice and therefore all the methods in it
thumbnail
Auditya manikanta Vadrevu, modificado 14 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Master Postagens: 621 Data de Entrada: 06/05/08 Postagens Recentes
hi amos,

thanks for ur reply. yes need to be care full with using it.

&

Using this method ${dateFormatDateTime.format($currentModifiedDate) iam able to get date in mm/dd/yy. Is there any other method to change the format to dd/mm/yy.


With Regards,
V.Auditya
thumbnail
Amos Fong, modificado 14 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
This is what I use to format my dates:

#set ($dateFormat = "MMMM d")
#set ($timeZone = $timeZoneUtil.getTimeZone("PST"))

#set ($displayDate = $dateUtil.getDate($eventStartDate, $dateFormat, $locale, $timeZone))
vasv kumar, modificado 12 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Junior Member Postagens: 46 Data de Entrada: 07/02/11 Postagens Recentes
To Get the themDisplay in CMS Temlates :

$request.theme-display


To Get Images Path :

$request.theme-display.path-theme-images
thumbnail
Pierpaolo Cira, modificado 9 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

Regular Member Postagens: 141 Data de Entrada: 26/02/10 Postagens Recentes
vasv kumar:
To Get the themDisplay in CMS Temlates :

$request.theme-display


To Get Images Path :

$request.theme-display.path-theme-images


It works for me! Thanks.
Pierre-François Fiat, modificado 8 Anos atrás.

RE: No $themeDisplay accessable in new Velocity Template

New Member Postagens: 7 Data de Entrada: 12/02/15 Postagens Recentes
from https://www.liferay.com/fr/community/forums/-/message_boards/message/15308871

#set ($serviceContext = $portal.getClass().forName("com.liferay.portal.service.ServiceContextThreadLocal").getServiceContext())
#set ($httpServletRequest = $serviceContext.getRequest())
#set ($objThemeDisplay = $httpServletRequest.getAttribute("THEME_DISPLAY"))

but in 6.2 the variable for theme display changes its name :

WebKeys.THEME_DISPLAY = "LIFERAY_SHARED_THEME_DISPLAY"

so I used :
#set ($objThemeDisplay = $httpServletRequest.getAttribute("LIFERAY_SHARED_THEME_DISPLAY"))