Foren

No $themeDisplay accessable in new Velocity Template

jeff gerbracht, geändert vor 15 Jahren.

No $themeDisplay accessable in new Velocity Template

Junior Member Beiträge: 65 Beitrittsdatum: 05.06.08 Neueste Beiträge
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é, geändert vor 15 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Legend Beiträge: 1197 Beitrittsdatum: 08.02.05 Neueste Beiträge
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, geändert vor 15 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Junior Member Beiträge: 65 Beitrittsdatum: 05.06.08 Neueste Beiträge
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, geändert vor 15 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Junior Member Beiträge: 65 Beitrittsdatum: 05.06.08 Neueste Beiträge
I've updated the wiki page for Journal Template/Velocity to more accurately reflect what variables are available in the velocity context.
nidhi singh, geändert vor 15 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Junior Member Beiträge: 57 Beitrittsdatum: 29.10.08 Neueste Beiträge
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, geändert vor 15 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Junior Member Beiträge: 65 Beitrittsdatum: 05.06.08 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Junior Member Beiträge: 43 Beitrittsdatum: 14.03.11 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Legend Beiträge: 1449 Beitrittsdatum: 10.10.07 Neueste Beiträge
I think you are missing the $ at $getterUtil.getLong($user_id)
thumbnail
Samir Gami, geändert vor 12 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Regular Member Beiträge: 162 Beitrittsdatum: 04.02.11 Neueste Beiträge
I think, class should be "com.liferay.portal.service.RoleLocalService", And "($getterUtil.getLong($user_id)))"
thumbnail
Auditya manikanta Vadrevu, geändert vor 14 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Master Beiträge: 621 Beitrittsdatum: 06.05.08 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Master Beiträge: 621 Beitrittsdatum: 06.05.08 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Master Beiträge: 621 Beitrittsdatum: 06.05.08 Neueste Beiträge
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, geändert vor 14 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Junior Member Beiträge: 46 Beitrittsdatum: 07.02.11 Neueste Beiträge
To Get the themDisplay in CMS Temlates :

$request.theme-display


To Get Images Path :

$request.theme-display.path-theme-images
thumbnail
Pierpaolo Cira, geändert vor 9 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

Regular Member Beiträge: 141 Beitrittsdatum: 26.02.10 Neueste Beiträge
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, geändert vor 8 Jahren.

RE: No $themeDisplay accessable in new Velocity Template

New Member Beiträge: 7 Beitrittsdatum: 12.02.15 Neueste Beiträge
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"))