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") />
Related
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}"/>
Using liferay 7 GA4 and freemarker engine.
We encountered a strange behaviour with the freemarker engine.
We have a bunch of web contents using all the same .ftl template.
Here is the begining of the template:
<#assign journalArticleId = .vars['reserved-article-id'].data>
<#assign journalArticleResourceLocalServiceUtil =
staticUtil["com.liferay.journal.service.JournalArticleResourceLocalServiceUtil"]>
<#assign assetCategoryLocalServiceUtil = staticUtil["com.liferay.asset.kernel.service.AssetCategoryLocalServiceUtil"]>
<#assign articleResourcePK = journalArticleResourceLocalServiceUtil.getArticleResourcePrimKey(groupId, journalArticleId)/>
<#assign categories = assetCategoryLocalServiceUtil.getCategories("com.liferay.journal.model.JournalArticle",articleResourcePK) >
<#list categories as category>
<#if category?is_first>
<#assign categorie = category.getName()>
</#if>
</#list>
<#assign serviceContext = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"].getServiceContext()>
<#assign themeDisplay = serviceContext.getThemeDisplay() />
<#assign currentUrl = themeDisplay.getPortalURL() + themeDisplay.getURLCurrent() />
And here is the error :
Error
On a public page we have an asset publisher listing all these web contents.
When clicking on one of these everything is fine and the web content is correctly rendered.
Now if we search for this web content via the search portlet, it's also correctly rendered.
The problem is : if we decide to search for the web content before using the asset publisher, the freemarker engine is not able to deal with the template.
In fact we got this kind of error.
The best part is that after you get the error via search, you still can't display it via the asset publisher. Everything is finally broken in that case.
I sincerely think that we tried every solution regarding freemarker engine (portal-ext.properties, freemarker allowed/restricted class etc).
I can't understand why if we come from any other page that can display these web contents it's working fine, but not at all if we search for it at strat.
Thanks for you help everybody.
Edited with template and error
Edit #2 : Here is the error when switching to serviceLocator :
serviceLocatorError
You don't need staticUtil to retrieve the DLFileEntryLocalServiceUtil, try to use the serviceLocator instead:
<#assign DLFileEntryLocalService = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryLocalService")>
NB.
You had to enable the serviceLocator in your templates:
Go to Control Panel -> Configuration -> System Settings -> Foundation -> FreeMarker Engine -> Restricted Variables and remove serviceLocator then restart Liferay.
I am using Liferay 7 as my content management system and freemarker as my template language.
How to get a small image url and also custom fields of my journal article?
I want to use those values in my ADT to render the articles in a custom way.
I got like this
First get the renderer from your current entry
<#assign renderer=curEntry.getAssetRenderer()>
Then get Journal Article from the renderer
<#assign article=renderer.getArticle()>
You can get all the custom fields from article variable
eg: for small image url
${article.getSmallImageURL()}
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 a code that creates a teamsite. After that I add some web parts to wiki web part zone(rich content area). In SharePoint 2010 user can change a text layout of the rich content in page edit mode.
Is there any way to programmatically change the text layout of the rich text area? I would want to set "two columns with header"-layout after site creation has completed.
My site is created like this.
site = elevatedSite.SelfServiceCreateSite(params.....);
rootWeb = site.RootWeb;
rootWeb.ApplyWebTemplate("STS#0");
SPListItem currentItem = rootWeb.Item;
var xhtml = currentItem[SPBuiltInFieldId.WikiField] as string;
Now I can modify the xhtml string and save it back to the page. I have tried to change it so that it contains exatly the same html structure which have created by sharepoint itself, when changing the text layout. After that change, actually it is not recognized as "two columns with header"-layout in sharepoint. It is still default one-column layout. Is there anybody who knows is it possible to change the text layout of the rich text area programmatically?
I found answer from here http://donalconlon.wordpress.com/2010/05/04/sp2010-creating-a-wiki-page-using-the-om/. SharePoint stores the information about used layout to the hidden span-element in wiki page.
For example, this presents two column layout without the header or footer.
<span id="layoutsData" style="display: none">false,false,2</span>
first false = no header
second false = no footer
2 = two columns
I have been looking for some information on doing the same thing. I found this blog post that checks out the page, edits the content then publish and approves it.
SharePoint 2010 change page content data through Object Model / API – Console Application
If you need to modify pure HTML content, its better to use cutom IHttpHandler (wrapped in dll) and connect it to SharePoint via web.config. Is is also allowing to modify dynamic content like AJAX responses.