I have created a structure in Liferay 7.2 that has an image selector. When I add the following to the ADT to get the image
<#assign
artImg = saxReaderUtil.createXPath("dynamic-element[#name='Imagean48']")
/>
it doesn't return the URL but instead returns a list.
<img src=" {" classpk":1923313,"groupid":"1912582","name":"spc_desktop_welcome_image3_benefits.jpg","alt":"man="" in="" suit","title":"spc_desktop_welcome_image3_benefits.jpg","type":"document","uuid":"db10a245-881c-d09c-ab64-4aeebc1581f0","fileentryid":"1923313","resourceprimkey":"2474428"}="" "="">
Is it possible to get just the URL of the image?
Evaluate artImg to a hash
<#assign
artImg = saxReaderUtil.createXPath("dynamic-element[#name='Imagean48']")
artImgHash = artImg?eval
/>
Get artImg DLFileEntry and then its URL
<#assign
dlFileEntryLocalService = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryLocalService")
dlURLHelper = serviceLocator.findService("com.liferay.document.library.util.DLURLHelper")
artImgDLFile = dlFileEntryLocalService.getFileEntryByUuidAndGroupId(artImgHash.uuid, artImgHash.grouId)
artImgURL = dlURLHelper.getImagePreviewURL(artImgDLFile, themeDisplay)
/>
Then you can just use it in your img
<img src="${artImgURL}"/>
Note: I've replicated your artImg = saxReaderUtil.createXPath... line but I don't think it works. The right way would be something like this:
<#assign
journal = entry.getAssetRenderer().getArticle()
rootElement = saxReaderUtil.read(journal.content).getRootElement()
artImg = rootElement.selectSingleNode("dynamic-element[#name='Imagean48']")
/>
Related
I am trying to use portletpreference in my nested webcontent in Liferay 7.4. In the 7.4 version, there are two tables [PortletPreferences] and [PortletPreferenceValue] for Preferences.
I am able to set the Preferences values but, having trouble in retrieving it in the template.
I have tried below code in my template for retriving the prefrences. I am not able to find any method which retrives PortletPreferenceValues.
<#assign portletPreferencesService = serviceLocator.findService("com.liferay.portal.kernel.service.PortletPreferencesLocalService") />
<#assign portletPreferncesValueService = serviceLocator.findService("com.liferay.portal.kernel.service.PortletPreferenceValueLocalService") />
<#assign portletKeys = staticUtil["com.liferay.portal.kernel.util.PortletKeys"]>
<#assign ownerId = groupId />
<#assign ownerType = portletKeys.PREFS_OWNER_TYPE_LAYOUT />
<#assign portletId = "com_liferay_journal_content_web_portlet_JournalContentPortlet" />
<#assign plid = 0/>
<#assign portletPreferences = portletPreferencesService.fetchPortletPreferences(ownerId, ownerType, plid, portletId) />
Can someone throw pointers on how to retrieve the same?
Thanks
Hello I've created a simple structure which only has 1 repeatable web content field. In my template I have the following code:
<#if WebContent75zf.getSiblings()?has_content>
<#list WebContent75zf.getSiblings() as cur_WebContent75zf>
<!-- Web Content Start -->
${cur_WebContent75zf.getData()}
<!-- Web Content End -->
</#list>
</#if>
The desired result would be either to show each web content rendered or at least get their data.
What I'm getting is the following and I'm wondering if I'm doing something wrong...
<!-- Web Content Start -->
{"className":"com.liferay.journal.model.JournalArticle","classPK":"40952"}
<!-- Web Content End -->
<!-- Web Content Start -->
{"className":"com.liferay.journal.model.JournalArticle","classPK":"40971"}
<!-- Web Content End -->
<!-- Web Content Start -->
{"className":"com.liferay.journal.model.JournalArticle","classPK":"40990"}
<!-- Web Content End -->
This: {"className":"com.liferay.journal.model.JournalArticle","classPK":"40971"} is what you need to retrieve the selected Web Content through the JournalArticleLocalService, you have just to get the classPK like this:
<#if WebContent75zf.getSiblings()?has_content>
<#list WebContent75zf.getSiblings() as cur_webContent>
<#assign cur_webContent_map = cur_webContent.getData()?eval>
<#assign cur_webContent_classPK = cur_webContent_map.classPK>
<#assign article = JournalArticleLocalService.getLatestArticle(cur_webContent_classPK?number)>
</#list>
</#if>
This works in Liferay 7.0. Make sure restricted variables are disabled in Liferay settings
<#-- Liferay 7.0 -->
<#-- Make sure restricted variables are disabled in Liferay settings -->
<#assign
serviceContext = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"].getServiceContext()
themeDisplay = serviceContext.getThemeDisplay()
group_id = themeDisplay.getScopeGroupId()
JournalArticleLocalService = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService")
>
<#if WebContent75zf.getSiblings()?has_content>
<#list WebContent75zf.getSiblings() as cur_webContent>
<#assign
cur_webContent_map = cur_webContent.getData()?eval
cur_webContent_classPK = cur_webContent_map.classPK
article = JournalArticleLocalService.getLatestArticle(cur_webContent_classPK?number)
article_id = article.articleId
article_content = JournalArticleLocalService.getArticleContent(group_id, article_id, null, locale, themeDisplay)
>
${article_content}
</#list>
</#if>
Define journalArticleLocalService before use it:
<#assign journalArticleLocalService = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService") />
I want to get the URL of Add Content to pass to an AJAX call.
In my Freemarker Template I assigned this variable:
<#assign addContentUrl = theme_display.getURLAddContent() />
Then, I passed this variable to my JavaScript function:
<script type="text/javascript">
var addUrl = "${addContentUrl}";
$.ajax({
url:addUrl,
...
});
</script>
The problem is that in the browser I do not get the URL but I get this function:
var addUrl = "Liferay.Dockbar.loadAddPanel();";
It is a bug of Liferay 6.2 or I did something wrong?
I fixed by including <#include init /> because theme_display.getURLAddContent() is defined in ROOT\html\themes\_unstyled\templates\init.ftl.
In my application i am using liferay-ui:input-editor .I want to get the value of input editor to a javascript variable, How to achieve that?? I have tried
<liferay-ui:input-editor />
<input name="<portlet:namespace />htmlCodeFromEditorPlacedHere" type="hidden" value="" />
function createPopUp(){
var url ="<%=fetchCandidateByIdForPhoneURL%>";
var type= "fetchCandidateInfo";
var candidateId = $('#candidateID').val();
var jobId = $('#JobList').val();
var text1 = $('#text1').val();
var text2 = $('#text2').val();
var text3 = $('#text3').val();
var interviewVenue = $('#interviewVenue').val();
var interviewCC = $('#interviewCC').val();
var interviewBCC =$('#interviewBCC').val();
var startDate = $('#start-date').val();
var interviewType = $('#interviewType').val();
var x ;
function <portlet:namespace />initEditor() {
return '<font style="font-weight: bold">scott was here</font>';
}
function <portlet:namespace />extractCodeFromEditor() {
var x = document.<portlet:namespace />fm.<portlet:namespace />htmlCodeFromEditorPlacedHere.value = window.<portlet:namespace />editor.getHTML();
alert(x);
}
But it is showing that
ReferenceError: _InterviewSchedule_WAR_InterviewScheduleportlet_initEditor is not defined error. How to resolve it and get the value in a javascript variable
Given the information provided in question, it seems that the javascript initialization function is missing for <liferay-ui:input-editor />. As pointed out in the tutorial here, which OP seems to be using (juding by variable names):
By default, the editor will call "initEditor()" to try and pre-populate the body of the editor. In this example, when the editor loads, it will have the value of "scott was here" in bold.
(...)
function <portlet:namespace />initEditor() {
return '<font style="font-weight: bold">scott was here</font>';
}
By default, the ck editor that Liferay uses will try to call the initEditor() javascript method to try and pre-populate the contents of the editor.
Therefore, you should define such a method, even if you return a blank string.
An example is given below:
<aui:script>
function <portlet:namespace />initEditor() {
return "<%= content %>";
}
</aui:script>
, where content is the string variable with the content you want to pass in when the editor is loaded. If you do not want to pass initial content then simply pass a black string.
I need to add a custom menu action to a custom content type programmatically in c#. This is because I will not know the URL I need to link to beforehand. The URL to link to will be pulled from configuration when the feature is activated.
I have tried the following:
Added the CustomAction in my Element.xml file as:
<CustomAction
Id="MyID"
RegistrationType="ContentType"
RegistrationId="0x010100ef19b15f43e64355b39431399657766e"
Location="EditControlBlock"
Sequence="1000"
Title="My Menu Item">
<UrlAction Url="" />
</CustomAction>
In my feature receiver FeatureActivated method, I have:
SPElementDefinitionCollection eleCollection =
properties.Feature.Definition.GetElementDefinitions(
new System.Globalization.CultureInfo(1));
foreach (SPElementDefinition ele in eleCollection)
{
if (ele.Id == "MyID")
{
System.Xml.XmlNode node = ele.XmlDefinition.FirstChild;
node.Attributes[0].Value = "MY URL";
ele.FeatureDefinition.Update(true);
}
}
I would expect this code to update the UrlAction Url with "MY URL" but it does not. If I hard code a URL in the XML it works but I must be able to do it programmatically.
You can use the SPUserCustomActionCollection on the SPWeb object:
using (SPSite site = new SPSite("http://moss.dev.com"))
using (SPWeb web = site.OpenWeb())
{
SPContentType contentType = web.ContentTypes["Curriculum Vitae"];
SPUserCustomAction action = web.UserCustomActions.Add();
action.RegistrationType = SPUserCustomActionRegistrationType.ContentType;
action.RegistrationId = contentType.Id.ToString();
action.Location = "EditControlBlock";
action.Sequence = 450;
action.Title = "Test";
action.Rights = SPBasePermissions.EditListItems;
action.Url = "http://www.google.com";
action.Update();
}
This way, you can set the URL to whatever you want. If you are updating an existing custom action, you can iterate through the collection and update the one you are looking for. Updating the element XML definition after you've installed the custom action doesn't do anything.
Depending on what you want to achieve, you can use some javascript;
<UrlAction Url="JavaScript:window.location='{SiteUrl}/_layouts/CustomListAction.aspx?ID={ListId}'"/>
the ~site and ~siteCollection also works:
<UrlAction Url="~site/_layouts/Page.aspx?ID={ListId}"/>
I don't think the WSS schema definition allows for an empty Url attribute in the UrlAction element. Maybe try putting a "default" url in the xml that you overwrite later?