Can someone tell me how to fetch the web content author image in web content template? When I tried with the user object, it's returning the current logged in user and not the actual one.
I can fetch the author name and id by using the key
<#assign authorId = .vars['reserved-article-author-id'].data>
<#assign authorName = .vars['reserved-article-author-name'].data>
I have used the below code to fetch the content author image but it returns the current loggedin user.
<#assign author-img = user.getPortraitURL(themeDisplay)>
But it is returning the current logged in user image
I have also tried with the taglib
<#liferay_ui["user-display"] userId="userId" />, but its failing with a message "Failed to set JSP tag parameter "author" (declared type: boolean, actual value's type: String). See cause exception for the more specific cause...
Thanks
I can't tell you about the solution from the top of my head, but here's what happens:
<#assign author-img = user.getPortraitURL(themeDisplay)>
uses the predefined variable user, e.g. the currently logged in user. Exactly what you get, but not what you want. themeDisplay is used to provide the current web context (e.g. host name that's being used) in, for proper URL generation that matches the currently displayed page.
Instead of using reserved-article-author-name, you want to use reserved-article-author-id to get hold of the user object with this id. You'll need UserLocalService for that (pardon my memory - I'm rarely using freemarker and would probably mess up how to actually do that, but you can search for that information. You might need access to the serviceLocator - which makes a good additional search term).
Having that user object (name it differently than user, e.g. author), you can get the author's portrait image URL with the same strategy as above:
<#assign author-img = author.getPortraitURL(themeDisplay)>
This is working.
<#assign userLocalService = serviceLocator.findService('com.liferay.portal.kernel.service.UserLocalService') />
<#assign author_id = .vars['reserved-article-author-id'].data?number>
<#assign author_user = userLocalService.getUserById(author_id)/>
<#assign author_image = author_user.getPortraitURL(themeDisplay)/>
<img src="${author_image}"/>
Related
I'm using a freemarker template to display web contents listed in an asset publisher.
In the template I'm trying to assign the portlet-namespace in order to use some asset features (like printing the entry) like this
<#attempt>
<#assign namespace = request["portlet-namespace"]>
<#recover>
<#assign namespace = 'undefined'>
</#attempt>
So, the print button is holding te code below
<a href="javascript:${namespace}printPage_0();" title='Print'>
printPage is the method used in liferay asset publisher code in asset_print.jspf
Well, everything is working fine: when inspecting the page in a browser, I verified that the namespace has been calculated and assigned to namespace variable as well (and no error displayed in UI). However, liferay portal logs the following each time a user tries to see the whole web content (ie. clicks on read more) from the asset publisher
Expression request["portlet-namespace"] is undefined on line
Anyone has seen this problem ? Is there another way to get the portlet-namespace in a freemarker template ?
#attempt/#recover is not for recovering from normal situations, and by default it logs the error when it recovers (so that the operators will be alerted). You should instead use the exp!default operator:
<#assign namespace = request["portlet-namespace"]!'undefined'>
(Though I'm not sure why printing undefinedprintPage_0(); makes sense, but that's a different issue.)
Hello i'm using Freemarker and i have to get the profile picture of user, i have the object user with the portraitId, but i don't know how get Theme Display for get the path or something... I've tried use this:
src="/image/user_male_portrait?img_id=${user.getPortraitId()}&img_id_token="
But i can't get the token, because i don't know :(
<#assign UserLocalService = serviceLocator.findService("com.liferay.portal.service.UserLocalService")>
<#assign user = UserLocalService.getUserById(27132)>
Someone know how get profile picture in freemarker?
I think the themeDisplay object already exists in liferay freemarker. So you can just call it as is.
Also the user object also has a method getPortraitUrl() that you can call to get the user's image directly.
You can retrive the user by doing
<#assign user = themeDisplay.getUser() />
and then display the profile picture (aka portrait in Liferay, but commonly called avatar) like this
<img src="${user.getPortraitURL(themeDisplay)}">
In my web content structure, I have a Document and Media type field so that users can select an image. In the web content template, I want to get the selected image's description so that I can fill in the alt text for the image.
How do I go about doing getting the description information of that selected image in the template?
You can get fields like description, you need to first get the image ID. Then you'll use the DLFileEntryLocalServiceUtil to get the file. Once you get the file, you can call the function to get the description.
<#assign imgID = Image.getData()?string?split("/")[5]?split("?")[0]>
<#assign fileEntry = staticUtil["com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil"]>
<#assign file=fileEntry.getFileEntryByUuidAndGroupId(imgID, groupId) >
${file.getDescription()}
You can get the other metadata of the document/image by calling one of the other functions for the DLFileEntryModel.
I have created structure with field "Link to page".
Now I want to display the link in ADT applied to content aggregator. How do I obtain the URL of the linked page?
I tried this approach, but it returns only some encoded-hash-something from the webcontent.
<#assign
docXml = saxReaderUtil.read(curEntry.getAssetRenderer().getArticle().getContent())
page_link = docXml.valueOf("//dynamic-element[#name='page_link']/dynamic-content/text()")
>
link to page
What kind of content you are working with? Web content or dynamic data lists?
If you have a web content structure with a link to page field and want to show it in a web content template use this to access the URL
...
If you want to access DDM fields in ADT try this
<#assign fields = storageEngine.getFields(DDMStorageId) />
<#assign contentLink = ddmUtil.getDisplayFieldValue(themeDisplay, fields.get("LinkToPage").getValue(), "ddm-link-to-page") />
I'm fairly new to Orchard and I'm wondering about the "best" way of building a basic list of documents with a download link?
Say the scenario is this, I want to make a list of newsletters, the news letter are in PDF format and the users should be able to download then straight from the list view.
An admin, should easily be able to add a new newsletter and it should turn up in the list.
My current train of thought is to, all through the dashboard,
create a content type "Newsletter" with a title field and a Media picker field, using the media picker field to upload the PDF file.
Then create a query, with the filter on Content type "Newsletter"
Create a projection pointing to the query
However, this only gives me a list of content items, showing their title as links back to the actual content item.
I've tried adding a layout to the query and set it to display properties instead of content. By doing that I can get a list where I can control the "output" a bit more. And I've gotten it to list the title and by doing a Rewrite and putting in the MediaPicker.Url, it also displays the URL in the list. This is all good but here I get stuck..
As the MediaPicker.URL outputs the url in the format like ~/media/default/xyz/filename.pdf, I cant just put it into a a href, it doesn't give a correct download link to the file.
Soo, question is, am I thinking and doing this totally the wrong way or am I missing something obvious? All ideas and suggestions and more then welcome.
Use or adapt the following template override in your theme:
#{
var url = Model.ContentField.Url;
}
#if(Model.ContentField.Url != null) {
if (url.StartsWith("~/")) {
url = Href(url);
}
<div class="media-picker-field attachment-pdf">
<span>download</span>
</div>
}
Modify the text as needed. This template was a Fields.MediaPicker-PDF.cshtml that was used for a media picker field named PDF.