Liferay Theme: get Portlet Window State - liferay

I'm building a freemarker theme for my liferay 6.2 and I'm struggeling with getting the window state of the login portlet when I'm trying to access a page without the needed permissions. In this case liferay "intercepts" the requests and renders a login portlet on top of my home layout template in maximized window state (which is a good behavior).
My problem is that my home layout looks different from my other layout templates. So the portlet is rendered with the wrong look and feel.
Is there a way to check if the login portlet is rendered or not and if it is get the viewmode to check if I want to render my home layout or not?
This is my code for home layout checks so far. The Todo-Comment is where I'm struggeling.
<#-- Check whether layout template of current page is home layout. -->
<#assign isHomeLayout = false />
<#if themeDisplay.getLayout().getTypeSettingsProperty("layout-template-id") == "novofleet-home-layout">
<#-- TODO: CHECK FOR LOGIN PORTLET AND WINDOW STATE AND RETURN FALSE IF PORTLET IS RENDERED AS MAXIMIZED -->
<#assign isHomeLayout = true />
</#if>

(Answer extracted from the question)
I just checked whether there is any portlet in maximized window state via Liferay's url params. New code:
<#-- Check whether layout template of current page is home layout. -->
<#assign isHomeLayout = false />
<#if themeDisplay.getLayout().getTypeSettingsProperty("layout-template-id") == "novofleet-home-layout">
<#assign isHomeLayout = true />
<#-- Check for existence of url parameter which forces portlets to maximezed window state and revoke home layout -->
<#assign maximized = request.getParameter("p_p_state")!"defaultValue" />
<#if maximized == "maximized">
<#assign isHomeLayout = false />
</#if>
</#if>

Related

Checking permissions in Liferay Application Display Template

I'm developing an application display template (freemarker) for the sitemap portlet to render in my layout in the pages footer. So far everything works. I can iterate through my pages and render the correct result. Checks on whether a page is hidden work as well.
Now I need one more feature. I want to check whether a page is accessible by logged users only (= don't show a link to a guest user when the page permissions forbid guests to see the page).
Here is my ADT code.
<#if entries?has_content>
<#list entries as entry>
<#assign layoutURL = portalUtil.getLayoutURL(entry, themeDisplay)>
<div class="grid3">
<ul>
<#if entry.isHidden() == false>
<li>${entry.getName(locale)}</li>
</#if>
</ul>
</div>
</#list>
</#if>
Maybe ${themeDisplay.getPermissionChecker()} can do the trick but I don't really have a clue on how to check for a users permissions on page. In a perfect world I can distinguish between different user groups but I'd settle for show when logged in, hide when anonymous (=guest).
I'm using Liferay 6.2. Anyone got an idea?
What you want to do is to check the view permission for a given page (Layout).
Freemarker snippet:
layoutPermission.contains(permissionChecker, entry.getPlid(), 'VIEW')
layoutPermission is available for all ADT templates and references LayoutPermission interface. entry means the current Layout instance.
I took the advice from this post on Liferay Forums.
To simply find out, if the user logged in you can call ThemeDisplay#isSignedIn.
Freemarker snippet:
<#if themeDisplay.isSignedIn()>
<#-- user is logged in -->
<#else>
<#-- user is guest -->
</#if>

Change the subsite Logo URL IN SharePoint

I have created a main site and I have created many subsite under the main site.
When I am in any main page and click on the logo icon, the page redirects to the home page.
But, when I am in any subsite and click on the logo icon, the page redirects to the subsite homepage rather than the main hompage.
I would like to change the navigation URL to the root site. Let me know if I have to edit any masterpage, or is there any common page that will inherit to all the child application.
Thanks
We have 2 ways to do this.
Method 1:
From the Snippet Gallery, copy and paste the default SiteLogo code snippet into your master page into the appropriate place you want it to be displayed.
In the SiteLogo code, search for SharePoint:SPSimpleSiteLink to find the relevant opening and closing tags. Now simply change the tag names to SharePoint:SPLinkButton instead.
Then simply add the attribute NavigateUrl to this tag and set it’s value to “~sitecollection/”.
Example:
Default snippet code:
<!--MS:<SharePoint:SPSimpleSiteLink runat="server" CssClass="ms-siteicon-a" ID="x7917ecc8c38d4bd69f58e338eab54c8c">-->
...
<!--ME:</SharePoint:SPSimpleSiteLink>-->
Should become this:
<!--MS:<SharePoint:SPLinkButton runat="server" NavigateUrl="~sitecollection/" CssClass="ms-siteicon-a" ID="x7917ecc8c38d4bd69f58e338eab54c8c">-->
...
<!--ME:</SharePoint:SPLinkButton>-->
Ref link
Method 2:
We are going to add custom js in the master page => our site is a publishing site
We find the site logo in the below hierarchy(in a rendered page).
<div id='DeltaSiteLogo'>
<a href='site url'>
<img src='siteIconPath.png/whatever extension'/>
</a>
</div>
So we may try the following for redirecting to the site collection/root web url on click of the logo.
// Add the following js in the '.html' design file that associates with the corresponding masterpage.
<script type="text/javascript">//<![CDATA[
$(document).ready(function(){
$("div#DeltaSiteLogo a").attr("href",_spPageContextInfo.siteAbsoluteUrl);
});
//]]>
</script>
It works.
Edit on the SharePoint Designer Master Pages > seattle.master .
Crtl F - Search for DeltaSiteLogo
DEFAULT:
<SharePoint:SPSimpleSiteLink CssClass="ms-siteicon-a" runat="server" id="onetidProjectPropertyTitleGraphic" >
<SharePoint:SiteLogoImage CssClass="ms-siteicon-img" name="onetidHeadbnnr0" id="onetidHeadbnnr2" LogoImageUrl="/_layouts/15/images/siteIcon.png?rev=47" runat="server"/>
</SharePoint:SPSimpleSiteLink>
Change To This (copy & paste the script):
<SharePoint:SPLinkButton runat="server" NavigateUrl="~sitecollection/" CssClass="ms-siteicon-a" ID="x7917ecc8c38d4bd69f58e338eab54c8c">
<SharePoint:SiteLogoImage CssClass="ms-siteicon-img" name="onetidHeadbnnr0" id="onetidHeadbnnr2" LogoImageUrl="/_layouts/15/images/siteIcon.png?rev=47" runat="server"/>
</SharePoint:SPLinkButton>

How to add custom portlet in Control Panel section

How can I add a custom portlet to the Portal section of the Control Panel, as shown in the following figure:
Here is how to do it:
In your portlet's liferay-portlet.xml (you can check the DTD of this xml for more information on other tags) include two tags in your <portlet> tag as shown:
<portlet>
<portlet-name>MyCustomPortlet</portlet-name>
<icon>/mycustom.png</icon>
<!--
These are the two entries which are required for the portlet
to appear in the control panel
-->
<!--
Set the control-panel-entry-category value to "my", "content",
"portal" or "server" to make this portlet available in the
Control Panel under that category.
-->
<control-panel-entry-category>portal</control-panel-entry-category>
<!--
Set the control-panel-entry-weight value to a double number
to control the position of the entry within its Control Panel
category. Higher values mean that the entry will appear lower
in the Control Panel menu.
-->
<control-panel-entry-weight>100</control-panel-entry-weight>
<instanceable>false</instanceable>
<header-portlet-css>/css/main.css</header-portlet-css>
<footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
<css-class-wrapper>mycustomportlet-portlet</css-class-wrapper>
</portlet>
Also, if you don't want your portlet to appear in the Add Menu so that it is not put on other pages, then in your liferay-display.xml you can include:
<display>
<category name="category.hidden">
<!--
Adding your portlet to the hidden category would not display
the portlet in the ADD Menu on the top-left-hand corner
-->
<portlet id="MyCustomPortlet"></portlet>
</category>
</display>
Build and deploy your portlet and you are good to go.
Apart from the Answer by Prakash K, ajaxable and instanciable should be false.

Setting Page.Title from the codebehind of a Sitecore sublayout (user control) doesn't work

I'm having an issue setting Page.Title for a page from the codebehind of a usercontrol (sublayout).
We have a layout, MainLayout.aspx. I can set the page title from the codebehind of this page, and it works fine. However, if, after this, I try to set the page title in the codebehind of MySublayout1, the new value is set for the Page.Title property, but the change is not reflected on the page.
I've tried moving the code from the Page_Load to the OnInit events for both the page and the control, but nothing seems to work. Any idea why this doesn't work?
The best approach for this is creating an new rendering or sublayout that renders the -section of your page. So you can set the values in literals or sc:text controls in the sublayout instead of setting only the Page.Title from codebehind.
This way you can set more properties all at once like the meta-keywords and meta-description, based on the current Sitecore Item.
I'd add the following to the layout or sublayout that is in it:
<head runat="server" id="_Head">
<title><sc:FieldRenderer ID="frTitle" runat="server" FieldName="title" /></title>
</head>
Also make sure that you call DataBind(); or set Sitecore.Context.State.DataBind to true.
If you want the Sublayout to override the title set in the Layout, you can move the code in the Layout to Page_Init and use Page_Load in your Sublayout.
If that doesn't work, then your Sublayout may have trouble accessing the Page. You can try using WebUtil.CurrentPage.Title to access the current page title. It might also require that you set runat="server" on the head and title elements as follows:
<head runat="server">
<title runat="server"></title>
You can simply use this:
< title> <%=Sitecore.Context.Item["PageTitleFieldName"] %> < /title>
It works fine to render page title from given field.

Custom Action for specific list view - SharePoint 2010

How can I target custom ribbon action menus for specific list views? I want to be displayed in the default view of the list but to be hidden in the other views.
Any ideas?
Though the question is old, yet unanswered , I am responding to it.
Create an empty Sharepoint Project in VS2010 , add an Elements.xml file in the project and past following XML in it.
<CustomAction Id="MyCustomButton" Sequence="999"
GroupId="Manage"
Location="CommandUI.Ribbon" // Location to display button
RegistrationId="101" // on every list, for a specific list or library put the GUID of list here e.g. RegistrationId="{GUID_OF_LIST}"
RegistrationType="List"
Rights="ManageWebs"
Title="Custom Document Library Button">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
<Button Id="Ribbon.Documents.Manage.Controls.CustomButton" TemplateAlias="o1"
ToolTipDescription="Creates a server side action."
ToolTipTitle="SSRibbon" LabelText="SS Action"
Image32by32="/_layouts/images/ContractClaims/newproject.jpg"
Image16by16="/_layouts/images/ContractClaims/newproject.jpg" Alt="New Project"
Command="{3E04C0C1-12DD-449E-905F-7E88EB9E22B1}"
Sequence="20"/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler Command="{3E04C0C1-12DD-449E-905F-7E88EB9E22B1}"
CommandAction="javascript:alert ('Hello World' ) ;" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
The several locations to display the button can be found here.For more on the top you can google respective XML elements.
You can use EnabledScript parameter in CommandUIHandler, where you can put javascript code and check if specific page/list/view is loaded.
link to similar answer
Example:
<CommandUIHandler
Command="Ribbon.ListItem.CustomGroup.Controls.BtnSayHello.Command"
CommandAction="javascript:alert('Hello');"
EnabledScript="javascript:
function isEnable(){
if(location.href.indexOf('AllItems.aspx') > 0){
return true;
}
return false;
}
isEnable();"
/>

Resources