I add the language portlet in my liferay theme using this code:
#set ($VOID = $velocityPortletPreferences.setValue('portletSetupShowBorders', 'false'))
#set ($portlet_id = '82')
#set ($instance_id = "239abc678iuy")
#set ($my_portlet_id = "${portlet_id}_INSTANCE_${instance_id}")
$theme.runtime($my_portlet_id, "", $velocityPortletPreferences.toString())
in the portal_normal.vm.
I use the same theme in many pages. The problem is when I change the configuration of the language portlet (e.g. add or delete some languages) the modification is only applied to the current page, not to other pages.
The preferences for the language portlet are unique per layout, that means every page has its own configuration for this portlet.
There is a setting in the liferay-portlet.xml which controls that. It defaults to true, thats why it isn't mentioned in the section for the language portlet.
You have two options:
Create an ext-plugin and redefine the language portlet in the liferay-portlet-ext.xml:
<portlet>
<portlet-name>82</portlet-name>
<icon>/html/icons/language.png</icon>
<struts-path>language</struts-path>
<!-- ... copy of all other lines of portlet 82 from liferay-portlet.xml -->
<preferences-unique-per-layout>false</preferences-unique-per-layout>
</portlet>
Create a hook plugin and create a service wrapper for the PortletLocalService, that returns a custom wrapper for portlet 82, that in the end returns false for preferencesUniquePerLayout.
Related
I have a portlet in liferay that shows list of items and allow to add/edit (add/save/list of items done by service builder).
Now I need separate liferay page with only add new functionality - can this be done with one portlet or should I copy it to separate portlet?
What I think I need:
way to open portlet with redirection to edit form (edit.jsp)
way to redirect to other liferay page with param (itemId) that would open that page on details.jsp and not standard view.jsp.
====
EDIT:
Now I do have links like that:
details:
<liferay-portlet:renderURL varImpl="rowURL">
<portlet:param name="backURL" value="<%= portletURLString %>" />
<portlet:param name="mvcPath" value="/html/details.jsp" />
<portlet:param name="itemId" value="<%= String.valueOf(item.getId()) %>" />
</liferay-portlet:renderURL>
add:
<liferay-portlet:renderURL varImpl="addURL">
<portlet:param name="mvcPath" value="/html/edit.jsp" />
</liferay-portlet:renderURL>
But they only work in the same portlet/page.
In liferay I have two public pages: "search/details" and "add".
On the "add" page this portlet should render edit.jsp (second url).
Then after an action I should redirect authorized user to "search/details" page with id of the newly created item and show its details.
I can create two portlets but I'm sure there is better and more liferayish solution to this problem.
You could set the default view with portlet preferences / custom configuration. Your portlet, P, can have a configuration parameter for the "type" of portlet A should be (in your case you have two types, "view" and "detail"). Based on this parameter, you can handle the render / action logic accordingly.
That way, with two layouts, L1 and L2, you can put an instance of P on L1 and set its type to "view". You can then put another instance of P on L2.
In P's components (ex. render command) you can check the type (view or detail) and you have control here over the render / action logic as per your use cases (the jsp you want to use, etc.)
For more information on configuration in liferay 7 see:
https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/transitioning-from-portlet-preferences-to-the-configuration-api
https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/making-your-applications-configurable
if you have a static layout of your site and you know what portlet will be placed where you can use the plid (page layout ID) parameter of the liferay-renderurl tag. That allows you to not only address portlets but also pages. The plid is usually loaded from some configuration.
Another trick how to reuse the existing code is to reuse the actual form and action classes and create only new portlet definitions. This expects that you use Liferay MVC + action command pattern.
your problem is a bit high level, but the solutions are the following techniques:
You can define a friendly URL for your portlet which will transfer the parameters directly in your portlet.
In your portlet you can react on the parameters an display whatever jsp you want.
If you defined the friendly url from 2. you can use it within a link easily:
Edit
If you can provide a bit of example code we can go more into detail.
No hard-n-fast rule to create separate portlets for view / add /
update actions. That totally depends on you.
You can achieve this using single (same) portlet on multiple pages, which default to listing view. Just set target="_blank" on the anchor(s) of the listing view for rowURL and addURL actions to open that link on new tab. The rest will be handled by portlet lifecycle to render specific view based on the portlet:param set for the URL.
The other way around can be the plain redirection to page with itemId=abc and action=add/update as queryString. and in doView of your portlet get that parameter from request and based on those parameters, filter inclusion of jsp.
I am trying to change the language of portlet title, but didn't succeed!
I went through the various link from liferay's forum, but unable to achieve my task.
Example:1
Example:2
Details:
I am using following locales fr_FR and zh_CN,with the following values in the concerned properties file
javax.portlet.title.1_WAR_microblogsportlet=News
javax.portlet.title.1_WAR_microblogsportlet=nouvelles(for fr_FR)
javax.portlet.title.1_WAR_microblogsportlet=新聞(for zh_CN)
resource bundle is set in portlet.xml as given:
<portlet-name>1</portlet-name>
<display-name>Microblogs</display-name>
<portlet-class>com.liferay.microblogs.microblogs.portlet.MicroblogsPortlet</portlet-class>
<resource-bundle>content.Language</resource-bundle>
You just need to have property with key as "javax.portlet.title", no need to put your portlet ID as part of key.
Name the localized properties files and put property value as below.
Language.properties
javax.portlet.title=News
Language_fr.properties
javax.portlet.title=nouvelles
Language_zh.properties
javax.portlet.title=新聞
Then liferay displays portlet in corresponding language depending on user's locale.
You may test in one of below ways.
For User -
In current user profile -> Display Settings, Select language as French and then visit the page having your portlet. It should display title in french instead of english.
Change in URL
You may also specify locale in page URL as described in liferay 6.1 documentation
http://localhost:8080/fr/<your page url>
Using Language portlet
Add Language portlet on your page and clicking on French flag changes locale to french and the page should display portlet title in French.
Liferay 6.2 CE
How exactly can one go about to set a portlet to show up on the highlighted category on the add application panel? I've been searching for hours, without any luck.
Have tried to define category name as "Highlighted", but it just creates a new one with the same name.
The main goal is just to have my own portlets sit on the top of the rest.
Cheers.
Configure the following settings (here with the defaults) in your portal-ext.properties:
##
## Dockbar Portlet
##
#
# Set the portlet ids that will be shown directly in the "Add Application"
# menu.
#
dockbar.add.portlets=56,101,110,71
Here you see that Liferay has the habit of numbering all the core portlets. Your own portlets ids will be constructed from their plugin name and the portlet id, e.g. the AmazingApp portlet that is deployed in the webapplication my-great-custom-plugins-portlet will have an ID of *amazingapp_WAR_mygreatcustompluginsportlet* (or similar). How can you find this out by yourself? Add it to the page, then choose "Look and Feel" and "Advanced Styling" - this will show the HTML id for your portlet, of which you can easily extract the actual portlet ID to use for portal-ext.properties.
I have a custom themed orchard site - I am new to Orchard.
All pages have the same header with primary navigation, and footer. I have set header & footer up as Zones.
There are 4 main sections, 2 require a second navigation on the left; Information & FAQ.
I would like to dynamically create pages for those sections in the CMS - and have the page added to the appropriate second navigation menu, then when clicked navigate to that page (showing the correct navigation menu on the left - with the right styling for the rest of the page).
In simple steps what's the best way to do this - and does it need me to edit the Layout or other files in Visual Studio (I can if required).
I have found several articles on this online - but they all apply to completed themes, not one being created from scratch.
(I also don't have this 'map' of the site on the widgets page - how / should I create one somehow?):
Thanks.
As i understood what you are after is creating a Widget. Basically to show any content in your page you must create appropriate ContentType and attach required parts to it , and to display it you must enter url of that content in browser's address bar or click in a link for that content which in either case it will navigate to a new page and will display content inside [Content] Zone. but if you want to display a Content in a special Zone and special pages, Creating a Widget is the way to go.to create a widget the only thing required is to add a WidgetPart to it and give it Stereotype of 'Widget'.you can do this by making following changes in Migration file for your desired ContentType :
ContentDefinitionManager.AlterTypeDefinition("MyType", cfg => cfg
.WithPart("WidgetPart")
.WithPart("CommonPart")
.WithSetting("Stereotype", "Widget"));
this will turn your Content Type into a widget which can be placed in any Zone you want.
to add your widget to a Zone navigate to widgets from dashboard.
and then select the zone which you want to place your widget in :
and then select your widget
and finally select the layer in which your widget will be shown.a layer is set of rules which determine in which pages your widget will be displayed.for example selecting homepage will display your widget only in home page, selecting default will display your widget in all pages and so on.to define your own rule check here.
Edit :
to create new zone in your theme just include the Zone name in theme.txt file then open up Layout.cshtml (one resides in your custom theme's view directory) , and do following :
given your zone name is SecondaryNavigation then add following code inside your theme
#if (Model.SecondaryNavigation != null)
{
<div id="secondary-navigation" class="group">
<div class="inner">
#Zone(Model.SecondaryNavigation)
</div>
</div>
}
with this an additional Zone will be displayed in zone list and then you can put your widget inside your newly created zone.and about that picture you asked about.it is an image file which created by author of the theme and named 'Theme.png' and will displayed as a preview in manage widget screen , you can create it for your own theme and put it in your theme view directory.
EDIT 2
The migration file itself is not important.the only thing which is important is to define a class which drives from DataMigrationImpl , orchar will pick your migration file and run it automatically , migration file has firstly a Create method which returns 1 , and for each further update you must define a method called UpdateFromN in which N is current version your module is in, that will return 2 , 3 , ... what you can do in a migration file is creating database tables , creating ContentTypes , ContentParts , ContentFields , etc. there is already couple of modules shipped with orchard , check them and get the idea.
I'd like to use custom fields to display some page specific strings in the theme.
I have created a custom field "intro" of type Textbox.
How do I access the data in the theme template (velocity)?
As there is no "introspection" which variables are declared, I find it very difficult to figure out how to access them. The documentation is far from usable on the topic of custom fields :-/
If you definde custom attribute in a page than you can use
$layout.getExpandoBridge().getAttribute("intro")
Also see javadoc or source for com.liferay.portlet.expando.model.ExpandoBridge
if you need use in template FTL, in my case for menu navigation template
<#assign prop = navItem.getLayout().getExpandoBridge().getAttribute("prop_name") >
Work for me in Liferay 7+:
Create a custom field type "site", fill data into site settings, and use into theme template for call this data into liferay theme:
If a VM file:
#set ($site_custom_field = $layout.getGroup().getExpandoBridge().getAttribute("site_custom_field_key"))
<h1>$site_custom_field</h1>
If a FTL file:
<#assign site_custom_field = layout.getGroup().getExpandoBridge().getAttribute("site_custom_field_key")>
<h1>${site_custom_field}</h1>
Have a nice day!