How to check logged user in liferay velocity? - liferay

I have a requirement that I have to display sign in url in webcontent, if user not logged in and also need to display if user logged I have to display sign out hyper link. I have searched somewhere got $is_signed_in is for checking user logged in or not. After that I have added the below code to my requirement. Even though user is logged or not it is displaying "To know more please Sign In". Why condition failed? and how to check user logged in or not in liferay velocity? I have observed that I am not getting the values of $is_signed_in,$sign_in_url,$sign_out_url
#if(!$is_signed_in)
To know more please Sign In
#else
click here to Sign Out
#end

$is_signed_in is available in themes, not in webcontent templates.
Try
#set ($themeDisplay = $httpServletRequest.getAttribute("THEME_DISPLAY"))
$themeDisplay.isSignedIn()
this should work in webcontent templates.
(Thanks #Gonzalo for the reminder to initialize $themeDisplay prior to use)

in your theme _diff/templates/portal_normal.vm, you have add this code.
if ($is_signed_in)
<!-- user dropdown starts -->
<div class="btn-group pull-right" >
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-user"></i><span class="hidden-phone"> $user_name </span>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>Logout</li>
</ul>
</div>
<!-- user dropdown ends -->
#end

Check the below link -
https://www.liferay.com/community/forums/-/message_boards/message/25175535
Try adding this code in portal-ext.properties
journal.template.velocity.restricted.variables=

Related

SVG icon breaks IE11 anchor tags

I have a problem where having an svg inside an a tag breaks a link that works in other browsers. The following code works in IE11:
<span class="login-user-name" *ngIf="isLoggedIn">
<a href="/auth/change-password" title="Change Password" attr.aria-label="Change Password Link">
Change your password
</a>
{{(user | async).displayName}}
</span>
However, the following works in other browsers, but not IE11. I was surprised the lack of relevant results I was able to find both on SO and google about SVGs not working inside tags on IE11:
<span class="login-user-name" *ngIf="isLoggedIn">
<a [routerLink]="['/auth/change-password']" title="Change Password" attr.aria-label="Change Password Link">
<svg-icon class="medium-gray tiny" icon="icon-torso" aria-hidden="true"></svg-icon>
</a>
{{(user | async).displayName}}
</span>
I don't totally understand the "why" of this, but one of the other developers solved it by simple substituting a tag for the . His only comment was "its the way inline elements work with nested items".
<div class="login-user-name" *ngIf="isLoggedIn">
<a class="change-password" [routerLink]="['/auth/change-password']" title="Change Password" attr.aria-label="Change Password Link">
<svg-icon class="medium-gray tiny" icon="icon-torso" aria-hidden="true">
</svg-icon>
</a>
{{(user | async).displayName}}
</div>

keystone.js Currently logged in user

I'm new to Keystone, but have been trying all day to find the currently logged in user name but I'm not clear how to do this.
If I take the index view from keystone for example
{{!< default}}
<div class="container">
<div class="jumbotron"><img src="/images/logo.svg" width="160">
<h1>Welcome</h1>
<p>This is your new <a href='http://keystonejs.com' target='_blank'>KeystoneJS</a> website.</p>
<p>
It includes the latest versions of
<a href='http://getbootstrap.com/' target='_blank'>Bootstrap</a>
and <a href='http://www.jquery.com/' target='_blank'>jQuery</a>.
</p>
<p>Visit the <a href='http://keystonejs.com/guide' target='_blank'>Getting Started</a> guide to learn how to customise it.</p>
<hr>
<p>We have created a default Admin user for you with the email <strong>masterofimps#yahoo.co.uk</strong> and the password <strong>admin</strong>.</p>
<p>Sign in to use the Admin UI.</p>
<hr>
<p>
Remember to <a href='https://github.com/keystonejs/keystone' target='_blank'>Star KeystoneJS on GitHub</a> and
<a href='https://twitter.com/keystonejs' target='_blank'>follow #keystonejs</a> on twitter for updates.
</p>
</div>
</div>
and I want to add the user name to the view code somthing like
<h1>Welcome Tim</h1>
I have tried
<h1>Welcome {{locals.user}}</h1>
<h1>Welcome {{locals.user.name}}</h1>
<h1>Welcome {{req.user}}</h1> (using an Express request)
But to no avail. How do I find the user name from the User model? Do I have to define something else in the ..\routes\views first?
If anyone could help with an example or pointer in the right direction, Id be very grateful indeed!
If you used the Yeoman generator, one of the middleware functions included (initLocals) sets the current user to a local variable.
res.locals.user = req.user;
https://github.com/keystonejs/generator-keystone/blob/master/app/templates/routes/_middleware.js#L27
You don't need to include locals before the variable name in Handlebars. So remove it in order to get the current user information.
{{user}}
{{user.name}}

How to disable specific shipping method based on product's attribute value from checkout process

From, order_wizard_shipmethod_module.tpl
I found this,
{{#each shippingMethods}}
<a data-action="select-delivery-option-radio"
class="order-wizard-shipmethod-module-option {{#if isActive}}order-wizard-shipmethod-module-option-active{{/if}}"
data-value="{{internalid}}">
<input type="radio" name="delivery-options" data-action="edit-module" class="order-wizard-shipmethod-module-checkbox"
{{#if isActive}}checked{{/if}}
value="{{internalid}}"
id="delivery-options-{{internalid}}" />
<span class="order-wizard-shipmethod-module-option-name">{{name}}
<span class="order-wizard-shipmethod-module-option-price">{{rate_formatted}}</span>
</span>
</a>
{{/each}}
I'm wondering how can I get product's attribute value within shopping cart and disable specific shipping method?
If you're looking for the attribute values of each shipping method, then go to the Javascript file OrderWizard.Module.CartSummary.js and in the getContext function, after the confirmation variable is defined, put in console.log(summary);.
In your Cart, look in the console and within attributes is shipmethod and you'll find what you need in there.

How to link to an entry in a channel in expressionengine?

I have the following code
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
{exp:channel:entries channel="static" sort="asc" dynamic="off"}
<li>{title}</li>
{/exp:channel:entries}
</ul>
</div><!--/.nav-collapse -->
Which is looping through a channel I have for static pages on my website. Technically it is showing all the stuff it should do. This is the code it outputs:
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Small Builders</li>
</ul>
</div>
However, when I click the link it gives me a white page. I have the htaccess from the documentation set up. I'm new to ExpressionEngine. Am I missing something completely obvious? I just want to link the the entry I've created.
If you try to go to abc.com/index/small-builders does it work? (added index)
I don't know if you're hiding index in the url or not but that can cause it.
The way I fixed this was the enable the Pages plugin on ExpressionEngine. Where I'm using ExpressionEngine 3.0.5 the plugin isn't installed/activated by default like it is on EE2.
Once this was activated I was able to assign templates and url structure no problem.
guess your post would be better on the expressionengine.stackexchange.com site.
Post it there and i´ll have a look if i can explain this to you

SharePoint 2010 WebPart Personalize Layout

I have a homepage on an Intranet. It has at 15+ webparts (news, weather, etc.) I want to allow the users to customize the page by moving the webparts around or deleting them. At present I don't let them see the ribbon at the top so they don't have access to the "Edit page" button. I have pulled it out from the Ribbon
<a unselectable="on" href="javascript:;" onclick="return false;" class="ms-cui-ctl-large" aria-describedby="Ribbon.WebPartPage.Edit.Edit.Menu.Actions.Edit_ToolTip" mscui:controltype="Button" role="button" style="height: auto;" id="Ribbon.WebPartPage.Edit.Edit-SelectedItem">
<span unselectable="on" class="ms-cui-ctl-largeIconContainer">
<span unselectable="on" class=" ms-cui-img-32by32 ms-cui-img-cont-float">
<img unselectable="on" alt="" src="/_layouts/1033/images/formatmap32x32.png" style="top: -160px; left: -96px;">
</span>
</span>
<span unselectable="on" class="ms-cui-ctl-largelabel" style="height: auto;">Edit<span unselectable="on">
</span>Page</span>
</a>
Unfortunately it is not working. Any thoughts?
I will be doing the same with the "Stop Editing" button as well.
According to this post: http://artykul8.com/2011/03/useful-sharepoint-shortcuts/
the trick is to use the MSOLayout_ToggleLayoutMode(); javascript function.
According to a comment in that same page, in SP2010, that javascript function is only available when you already have a web part in the page. The behavior I observed differs from this one, given that, to me, this function only worked when the page was in edit mode already (and it worked even when the page had no web part added).
I was able to find the javascript file where that function is defined, which is the ie55up.js. You can load it in your masterpage by doing:
<SharePoint:ScriptLink language="javascript" name="ie55up.js" OnDemand="false" runat="server" />
For information about how to build a web control that uses that javascript function, see here: http://www.codeproject.com/KB/sharepoint/SwitchWPMode.aspx
Hope this helps
I finally found the answer to this question. It was very simple after the JS call was determined. I believe this should be for a webpart only page.
To put the page in edit mode for Personalization via a Javascript call:
ChangeLayoutMode(true); // how simple is that??
To stop the editing of the page via a Javascript call:
MSOLayout_ToggleLayoutMode(); // same as given in the other post
The "Stop" edit mode I believe is the same for all pages no matter if it's a personalized page, all webparts page, etc.

Resources