Image Description in Liferay Web Content Template - liferay

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.

Related

Get small image url to ADT Liferay 7

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()}

How do I get a relative URL to a media item from my codebehind?

I have a layout web part which has a "Teaser" field. The "Teaser" field uses a "media selection" form control. In this case the field is set to an image uploaded to one of the sites media libraries.
I want to render that image, so I'm trying to get the relative URL to it in the codebehind:
if (Teaser != Guid.Empty) // Teaser is {8d7fa1ab-b304-474f-9ab9-2e17e8fee84f}
{
var mediaInfo = MediaFileInfoProvider.GetMediaFileInfo(Teaser, SiteContext.CurrentSiteName);
// mediaInfo is null so the next line crashes
var libraryInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(mediaInfo.FileLibraryID);
string url = MediaFileURLProvider.GetMediaFileUrl(mediaInfo, SiteContext.CurrentSiteName, libraryInfo.LibraryFolder);
The "mediaInfo" variabe is null, so the code crashes.
How can I get a relative URL to my media file?
You cannot add the "Media selection" form control in combination with an field type Guid. Then you need to create an custom form control if you need to have only the Guid.
But an better solution is add an field with the data type "text" and in combination with the form control "media selection" then adds directly the relative URL inside the field when selecting an image from the media library.
If you also need the MediaInfo then you can get this object with the parameter "mediaFilePath", like described here : https://devnet.kentico.com/docs/8_2/api/html/M_CMS_MediaLibrary_MediaFileInfoProvider_GetMediaFileInfo_3.htm
Good luck and if you have more questions you can always ask them here on StackOverflow or on http://devnet.kentico.com/questions-answers.
If this answer helped you, please vote for my answer :-)

Display image with Projection in Orchard 1.7

how to display image with with Projection in Orchard 1.7.
i have try but not able to get image its sow me ID with select html layout and custom display html.
can some on help me to get image with orchard projection/query
==Updated Post
I have one Query to select all company name (input text) , detail (input text) and company image, i want to show a list of all company name with image thumb on front site with projection and query ...list is coming but how to get image that is the problem.
thanks
If you're using ImagePart you should be able to access to MediaPart. MediaPart has FolderPath and FileName property. Just do something like this: Image.As.FolderPath to access to it in your shape.
If you are not using ImagePart, be more specific (e.g. showing some code)

Building a list of downloadable items in Orchard 1.6

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.

Cannot Display Image from List

I'm trying to display ListItems in a GridView.
I am able to access the list items but my image is getting displayed as url .
I am using:
dr["Category"] = SPEncode.HtmlEncode(Convert.ToString(oListItem["Category"]));
The above line of code displays the list items, but when I try to display the images, it renders as http://server/images/xyz.jpg in the gridview.
Please help me in accessing the list images.
Update:
With regard to Alan's answer:
I have tried this:
foreach (SPListItem oListItem in collListItems) {
dr["Category"] =
SPEncode.HtmlEncode(Convert.ToString(oListItem["Category"]));
}
But when i try to display the images:
dr["ProductImage"] =
SPEncode.HtmlEncode(Convert.ToString(oListItem["ProductImage"]));
It still renders as: http://server/images/xyz.jpg in the gridview.
This question could use a few more details. It would help to know what oListItem[key] and dr[key] were arrays of. Whatever it is, it looks like oListItem[].ToString() method just returns a URL.
Couldn't you just new up an Image control, set the ImageSrc propery, and then add it into the GridView? You need to instantiate a new Image with each row (don't reuse an Image).
Are you using the ASP.NET GridView?
In that case you can set the filed property to your image column to Image Field.
Then you can assign the value of your converted oListItem["ProductImage"] field to the PictureUrl field.
Here's an example to get you started:
http://msdn.microsoft.com/en-us/library/aa479350.aspx
You can try the solution provided here:
http://cipriangrosu.blogspot.com/2009/05/display-item-type-icon-in-spgridview.html

Resources