掲示板
No $themeDisplay accessable in new Velocity Template
15年前 に jeff gerbracht によって更新されました。
No $themeDisplay accessable in new Velocity Template
Junior Member 投稿: 65 参加年月日: 08/06/05 最新の投稿
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.
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
#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
15年前 に Ray Augé によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Liferay Legend 投稿: 1197 参加年月日: 05/02/08 最新の投稿
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.
Then in your template do:
I'm not sure what you need from $themeDisplay, but let me know and I'll let you know if it's possible.
[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.
15年前 に jeff gerbracht によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Junior Member 投稿: 65 参加年月日: 08/06/05 最新の投稿
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
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
15年前 に jeff gerbracht によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Junior Member 投稿: 65 参加年月日: 08/06/05 最新の投稿
I've updated the wiki page for Journal Template/Velocity to more accurately reflect what variables are available in the velocity context.
15年前 に nidhi singh によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Junior Member 投稿: 57 参加年月日: 08/10/29 最新の投稿
hi
I want to know there is any velocity variable for user Role, i have to use in Journal content.
please help me
I want to know there is any velocity variable for user Role, i have to use in Journal content.
please help me
15年前 に jeff gerbracht によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Junior Member 投稿: 65 参加年月日: 08/06/05 最新の投稿
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"))
12年前 に Marc Piparo によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Junior Member 投稿: 43 参加年月日: 11/03/14 最新の投稿
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!
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!
12年前 に Thiago Leão Moreira によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Liferay Legend 投稿: 1449 参加年月日: 07/10/10 最新の投稿
I think you are missing the $ at $getterUtil.getLong($user_id)
12年前 に Samir Gami によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Regular Member 投稿: 162 参加年月日: 11/02/04 最新の投稿
I think, class should be "com.liferay.portal.service.RoleLocalService", And "($getterUtil.getLong($user_id)))"
14年前 に Auditya manikanta Vadrevu によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Liferay Master 投稿: 621 参加年月日: 08/05/06 最新の投稿
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
then from template i have tried with this,
1.
and also with
2.
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
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
14年前 に Amos Fong によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Liferay Legend 投稿: 2047 参加年月日: 08/10/07 最新の投稿
Hey Auditya,
This property is actually a list of restricted variables. So you want to add this to portal-ext.properties:
This property is actually a list of restricted variables. So you want to add this to portal-ext.properties:
journal.template.velocity.restricted.variables=
14年前 に Auditya manikanta Vadrevu によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Liferay Master 投稿: 621 参加年月日: 08/05/06 最新の投稿
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
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
14年前 に Amos Fong によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Liferay Legend 投稿: 2047 参加年月日: 08/10/07 最新の投稿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
14年前 に Auditya manikanta Vadrevu によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Liferay Master 投稿: 621 参加年月日: 08/05/06 最新の投稿
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
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
14年前 に Amos Fong によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Liferay Legend 投稿: 2047 参加年月日: 08/10/07 最新の投稿
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))
12年前 に vasv kumar によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Junior Member 投稿: 46 参加年月日: 11/02/07 最新の投稿
To Get the themDisplay in CMS Temlates :
To Get Images Path :
$request.theme-display
To Get Images Path :
$request.theme-display.path-theme-images
9年前 に Pierpaolo Cira によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
Regular Member 投稿: 141 参加年月日: 10/02/26 最新の投稿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.
8年前 に Pierre-François Fiat によって更新されました。
RE: No $themeDisplay accessable in new Velocity Template
New Member 投稿: 7 参加年月日: 15/02/12 最新の投稿
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"))
#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"))