我正在通过钩子安装布局
的友好url如下
/cat1/link1/cat1 link2
和
/cat2/link3/cat2 link4
我希望当我导航到cat1/link1
时导航链接应为link1和link2
当我导航到cat2/link3
导航链接应为link3和link4
我怎样才能做到这一点?
或者谁能建议我如何将多个站点的布局分组到不同的类别在同一生活方式安装?
谢谢. .
创建组织(这是来自七齿轮StartupAction.java
)
long userId = defaultUserId;
long parentOrganizationId = OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID;
String name = "7Cogs, Inc.";
String type = OrganizationConstants.TYPE_REGULAR_ORGANIZATION;
boolean recursable = true;
long regionId = 0;
long countryId = 0;
int statusId = GetterUtil.getInteger(PropsUtil.get("sql.data.com.liferay.portal.model.ListType.organization.status"));
String comments = null;
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddCommunityPermissions(true);
serviceContext.setAddGuestPermissions(true);
Organization organization =
OrganizationLocalServiceUtil.addOrganization(
userId, parentOrganizationId, name, type, recursable, regionId,
countryId, statusId, comments, serviceContext);
Group group = organization.getGroup();
GroupLocalServiceUtil.updateFriendlyURL(group.getGroupId(), "/7cogs");
你确定你需要两个组织而不是两个社区吗?
更新评论中的问题:
要在主题(velocity)中获取组织名称,您可以使用(如果您在组织的页面(组)中)
在portal-ext.propertiesjournal.template.velocity.restricted.variables=
主题虚拟机文件
Liferay 6
#set($os = $serviceLocator.findService("com.liferay.portal.service.OrganizationLocalService"))
#set($organization = $os.getOrganization($themeDisplay.getScopeGroup().getOrganizationId()))
$organization.getName()
5. Liferay x
#set($os = $serviceLocator.findService("com.liferay.portal.service.OrganizationLocalServiceUtil"))
#set($organization = $os.getOrganization($themeDisplay.getScopeGroup().getOrganizationId()))
$organization.getName()
编辑:如果您的用户是组织的成员,那么您可以使用
#foreach($org in $themeDisplay.getUser().getOrganizations())
$org.getName()<br>
#end
请注意,用户可以是多个组织的成员,您将获得所有组织的成员。
您需要了解的代码:
从Martin提到的同一个类中,我已经组合了一组代码,可以实现您所需要的。
注意,有些变量没有定义。您必须使用针对您的Liferay安装的正确值。例如,userId可以是任何人,但我建议使用默认用户的userId或管理员的userId。
代码:
Organization organization =
OrganizationLocalServiceUtil.addOrganization(
userId, OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID,
"My Org 1", OrganizationConstants.TYPE_REGULAR_ORGANIZATION, true,
regionId, countryId, statusId, comments, true, serviceContext);
Group group = organization.getGroup();
GroupLocalServiceUtil.updateFriendlyURL(group.getGroupId(), "/cat1");
LayoutLocalServiceUtil.addLayout(
group.getCreatorUserId(), group.getGroupId(), "false",
LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "My Link 1", StringPool.BLANK,
StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, "/link1",
false, serviceContext);
LayoutLocalServiceUtil.addLayout(
group.getCreatorUserId(), group.getGroupId(), "false",
LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "My Link 2", StringPool.BLANK,
StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, "/link2",
false, serviceContext);
organization =
OrganizationLocalServiceUtil.addOrganization(
userId, parentOrganizationId, name, type, recursable, regionId,
countryId, statusId, comments, true, serviceContext);
group = organization.getGroup();
GroupLocalServiceUtil.updateFriendlyURL(group.getGroupId(), "/cat2");
LayoutLocalServiceUtil.addLayout(
group.getCreatorUserId(), group.getGroupId(), "false",
LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "My Link 3", StringPool.BLANK,
StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, "/link3",
false, serviceContext);
LayoutLocalServiceUtil.addLayout(
group.getCreatorUserId(), group.getGroupId(), "false",
LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "My Link 4", StringPool.BLANK,
StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, "/link4",
false, serviceContext);