I know how to get groupid in liferay velocity theme using:
#set ($scopeGroupId = $getterUtil.getLong($group_id))
However I also need to get a folder's ID using its name.
I have been researching for a while and don't seem to find a way to do that.
Q: Is this enabled and feasible in liferay 6.2?
Make sure that you are allowed to use serviceLocator or add in your portal-ext.properties this entry:
velocity.engine.restricted.variables=
After that you can use this code in your template:
#set ($folderLocalService =$serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFolderLocalService"))
#set ($folderId = $folderLocalService.getFolder($groupId,0,"folder_name").getFolderId())
$folderId
Or you can use another method from DLFolderLocalService.
Related
I am trying to use serviceLocator in the velocity template for journal article in Liferay.
I modified the portal-ext.properties file by adding line:
journal.template.velocity.restricted.variables=
Then i restarted the server
In my vm file I have:
#set ($countryService = $serviceLocator.findService("com.liferay.portal.service.CountryService"))
#set ($countryList = $countryService.getCountries())
#foreach ($country in $countryList)
$country.getName()
#end
This displays nothing in the article and also gives no error on the server. I also checked the database and countries are there and if I am using getCountries() method in my portlets service it returns countries as it should.
Has anybody had a similar problem ?
I figured out what I was doing wrong.
In the portal-ext.properties firstly I was setting:
journal.template.velocity.restricted.variables=
But instead that, it sholud be:
velocity.engine.restricted.variables=
Right now I am using the default portal_normal.vm to display my page. I have made some changes to custom.css to give some look to the theme (JUst changed the colour of the background)
I have made some changes to the portal_normal.vm.
What if I want to give a complete different look to my page ? My answer is make changes to the portal_normal.vm page.
MY question is :
portal_normal.vm has some variables and stuff like:
<html class="$root_css_class" dir="#language ("lang.dir")" lang="$w3c_language_id">
I would like to know where does portal_normal.vm get these values from? By values I mean values of variables like $root_css_class ? Usually velocity gets these values from a java class. So in liferay theme, from where does portal_normal.vm get these values from? Is it ok to change the portal_normal.vm file completely?
Yes you can change any thing in portal_noraml.vm file and you design your own look.
Here to change portal_normal.vm we will use theme. in _diff/templates place classic theme portal_normal.vm and do changes.
All velocity variable are declared in init.vm file and we have another file called inti_custom.vm for declare our own velocity related variables.
Most of the velocity variables which required for portal already defined by liferay people we just use those.
Use init_custom.vm in _diff/templates folder for custom velocity varibles.
https://github.com/liferay/liferay-portal/blob/6.2.x/portal-web/docroot/html/themes/_unstyled/templates/init.vm
Most of the variables already loaded by velocity engine so max we dont need to create new variables in velocity engine.
You can create theme in liferay and provide customization in portal_normal.vm.
There is init.vm file where some of the variables are declared and also VelocityVariablesImpl.java is the class where vm variables are defined.
How can I get the title of current page in a CMS velocity template ?
I need the same String as is shown in the last part of the breadcrump, in other words, the page title.
Finally I found out how to do it.
It's necessary to access through the $themeDisplay
##Take layout id
#set ($layoutId = $request.get("theme-display").get("plid"))
## get the service for layout
#set($layoutService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))
##convert the layout id into long
#set ($layoutLong = $getterUtil.getLong($layoutId))
##take a layout object
#set($layout = $layoutService.getLayout($layoutLong))
#set ($pageName = $layout.getName($locale))
That's it.
In a theme template: $page.getHTMLTitle($locale)
From a CMS template I'll have to dig a bit deeper for the answer... let me know if the theme is sufficient
In addition with larrytron code, It's usefull to declare this line in portal-ext.properties to use restricted variables in CMS Template
journal.template.velocity.restricted.variables=
Does anyone know if it's possible to override the DisplayType template for a ContentType using the an url alternate template? For example, is it possible to override the template:
Content-Page.Detail.cshtml with Content-url-homepage-Page.Detail.cshtml? After playing around a bit, it does not seem so. Does anyone know if what I'm trying to achive is possible?
Thanks!
You can view all available alternates for a shape by enabling the 'Shape Tracing' feature and viewing the list of alternates e.g. http://devhammer.net/blog/Customize-Orchard-CMS-with-Designer-Tools
For example on the main content item of the homepage I get out of the box:
~/Themes/MyTheme/Views/Content.cshtml
~/Themes/MyTheme/Views/Content-url-homepage.cshtml
~/Themes/MyTheme/Views/Content.Detail.cshtml
~/Themes/MyTheme/Views/Content-Page.cshtml
~/Themes/MyTheme/Views/Content-10.cshtml
~/Themes/MyTheme/Views/Content-Page.Detail.cshtml
~/Themes/MyTheme/Views/Content-10.Detail.cshtml
Your options are to add or extend existing alternate factories such as Orchard.DesignerTools.Services.UrlAlternatesFactory e.g.
// appends [ShapeType]__url__[Url]_[DisplayType] alternates
context.ShapeMetadata.Alternates = _urlAlternates.Value.Select(url =>
context.ShapeMetadata.Type + "__url__" + url + "_" +
context.ShapeMetadata.DisplayType)
.Union(context.ShapeMetadata.Alternates)
.ToList();
This will give you the alternate
~/Themes/MyTheme/Views/Content-url-homepage.Detail.cshtml
or to use one of the existing alternates such as
~/Themes/MyTheme/Views/Content-10.Detail.cshtml
Which looks like it might suit your purposes (to me using the id is not as clean as using the url)
I also tried adjusting the feature priority of the 'Url Alternates' feature so that the url alternates are appended to all the other existing alternates as it appears from the code was intended, but as far as I can see this is not working or otherwise not supported.
I'm creating a set of custom structures (and matching templates) for Web Content Displays on a Liferay site.
To make things more convenient for site maintainers, I would like one of these templates to suppress look-and-feel borders by default.
I've found documentation and samples online showing how to disable borders for portlets that are embedded in the theme, but I haven't had any luck applying those techniques inside a WCD template.
Here's the code I've seen embedded in a theme:
#set ($VOID = $velocityPortletPreferences.setValue("portlet-setup-show-borders", "false"))
#set ($VOID = $theme.runtime("customportletname_WAR_pluginname", "", $velocityPortletPreferences.toString()))
$velocityPortletPreferences.reset()
Here is how I've applied it to my template:
#set ($VOID = $velocityPortletPreferences.setValue("portlet-setup-show-borders", "false"))
<div class="custom-wcd wcdnormal">
<h2>$title.getData()</h2>
$content.getData()
</div>
$velocityPortletPreferences.reset()
I'm not surprised that it didn't work -- there's nothing analogous to the $theme.runtime call that applies the prefs to a portlet, but I also don't know whether $theme.runtime is appropriate at this layer, and if it is, what value to supply as the first argument. I suspect this last is the most likely alternative, but I don't know how to identify the WCD portlet to $theme.runtime, nor do I know how to track that information down (I'm not a Java dev by any stretch).
And just to clarify: it is not acceptable to disable borders on all portlets by default, nor am I in a position to modify the Java controller that consumes journal-article components at render-time.
Any advice is appreciated.
Simple and direct:
$velocityPortletPreferences.setValue("portletSetupShowBorders", "false")
$velocityPortletPreferences.setValue("languageIds", "pt_BR,en_US")
$velocityPortletPreferences.setValue("displayStyle", "1")
$theme.runtime("82", "", $velocityPortletPreferences.toString())
$velocityPortletPreferences.reset()
This example is for embed the language portlet (Portlet ID = 82), direct in one of .vm theme files, in my case this code is on navigation.vm.
Liferay property/preference names have a tendency to change sometimes. I created a hook this week to create a site, populate it with pages containing portlets and also to provision the CMS with a default set of structures, templates and articles. I too had to turn off the borders for my portlets and needed to set the following preference name to false to achieve that: portletSetupShowBorders
I java code it did this as follows:
PortletPreferences prefs = PortletPreferencesFactoryUtil.getLayoutPortletSetup(page, portletInstanceId);
prefs.setValue("groupId", String.valueOf(page.getGroupId()));
prefs.setValue("articleId", article.name());
prefs.setValue("portletSetupShowBorders", "false");
prefs.store();
From a Liferay Journal Template you should be able to use the following code to turn of the borders of the portlet that will show an article that uses the template:
#set ($portletPreferencesService = $serviceLocator.findService('com.liferay.portal.service.PortletPreferencesLocalService'))
#set ($companyId = $getterUtil.getLong($companyId))
#set ($ownerId = 0) ## PortletKeys.PREFS_OWNER_ID_DEFAULT
#set ($ownerType = 3) ## PortletKeys.PREFS_OWNER_TYPE_LAYOUT
#set ($plid = $getterUtil.getLong($request.theme-display.plid))
#set ($portletId = $request.theme-display.portlet-display.id)
#set ($portletPreferences = $portletPreferencesService.getPreferences($companyId, $ownerId, $ownerType, $plid, $portletId))
#set ($VOID = $portletPreferences.setValue('portlet-setup-show-borders', 'false'))
#set ($VOID = $portletPreferences.store())
Just remember that you also need to add the following line to your portal-ext.properties:
journal.template.velocity.restricted.variables=