Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Webpart Questions View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
dion.tsai-adrenalinmedia.com - 10/5/2011 7:51:29 PM
   
Webpart Questions
Hi there,

I have a document type including some images fields both direct uploader and image selection. I have successfully showed the image in transformation using the code below.


<tr>
<td>Direct Uploader :</td>
<td><%# IfEmpty(Eval("ArticleImage"), "", GetImage("ArticleImage")) %></td>
</tr>
<tr>
<td>Direct Uploader (resized):</td>
<td><%# IfEmpty(Eval("ArticleImage"), "", GetImage("ArticleImage", 160, 160, 120, Eval("ArticleTitle"))) %></td>
</tr>
<tr>
<td>Image Selection :</td>
<td><%# IfEmpty(GetDocumentUrl("test",""), "", GetImageByUrl(GetDocumentUrl("test","")))%></td>
</tr>
<tr>
<td>Image Selection (resized):</td>
<td><%# IfEmpty(GetDocumentUrl("test",""), "", GetImageByUrl(GetDocumentUrl("test",""), 100, 100, 100, Eval("ArticleTitle")))%></td>
</tr>


Now but i am looking for show document type data in custom webpart. I am using .net repeater to render the data.

However, I got the error message, The name 'IfEmpty' does not exist in the current context, which I realized those functions are only available in CMSAbstractTransformation.

What do I suppose to do to render document type images (both direct uploader and file selection fields) in custom webpart?


The ascx file

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FeatureArticles.ascx.cs"
Inherits="CMSWebParts_RealInsurance_Common_LearningCentre_FeatureArticles" %>
<%@ Import Namespace="CMS.WorkflowEngine" %>
<h2>
FeatureArticle</h2>
<table>
<asp:Repeater runat="server" ID="rprFeatureArticle">
<ItemTemplate>
<tr>
<td>
Direct Uploader :
</td>
<td>
<%# IfEmpty(Eval("ArticleImage"), "", GetImage("ArticleImage")) %>
</td>
</tr>
<tr>
<td>
Direct Uploader (resized):
</td>
<td>
<%# IfEmpty(Eval("ArticleImage"), "", GetImage("ArticleImage", 160, 160, 120, Eval("ArticleTitle"))) %>
</td>
</tr>
<tr>
<td>
Image Selection :
</td>
<td>
<%# IfEmpty(GetDocumentUrl("test",""), "", GetImageByUrl(GetDocumentUrl("test","")))%>
</td>
</tr>
<tr>
<td>
Image Selection (resized):
</td>
<td>
<%# IfEmpty(GetDocumentUrl("test",""), "", GetImageByUrl(GetDocumentUrl("test",""), 100, 100, 100, Eval("ArticleTitle")))%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>


Code behind

public partial class CMSWebParts_RealInsurance_Common_LearningCentre_FeatureArticles : CMSAbstractWebPart
{
protected CMSAbstractTransformation Helper;
protected TreeProvider tree;

protected void Page_Load(object sender, EventArgs e)
{
Helper = new CMSAbstractTransformation();

UserInfo ui = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserID);
tree = new TreeProvider(ui);

TreeNode document = CMSContext.CurrentDocument;

DataSet dsLandingFeatureArticles = tree.SelectNodes(CMSContext.CurrentSiteName, document.NodeAliasPath + "/Feature/%", CMSContext.CurrentDocumentCulture.CultureCode, true, "RealInsurance.Article", string.Empty, "NodeOrder", 1);
if (dsLandingFeatureArticles != null)
{
rprFeatureArticle.DataSource = dsLandingFeatureArticles;
rprFeatureArticle.DataBind();
}
}
}



User avatar
Member
Member
kentico_michal - 10/6/2011 3:18:27 AM
   
RE:Webpart Questions
Hello,

The methods of CMSAbstractTrasformation class can be used only in the transformation. It means that you will need to use CMSRepeater control instead of standard .NET repeater. In general, CMSRepeater inherits from NET repeater so it provides all properties you are familiar with from .NET repeater. CMSRepeater control has property called TransformationName where you need to specify transformation you want to use.

For more infomation about this control I would like to point you at this section of Control’s guide:
CMSRepeater overview.


Best regards,
Michal Legen

User avatar
Certified Developer v7
Certified  Developer v7
dion.tsai-adrenalinmedia.com - 10/7/2011 1:11:10 AM
   
RE:Webpart Questions
Hi there,

As recommended, I used the Kentico Basic Repeater because it allows me to bind the data using tree.SelectNodes method in code behind. However, i still have the same error. Looks like even if I am using the Kentico Repeater control, I still can not use the methods in CMSAbstractTransformation in the WebPart since it is inherited from CMSAbstractWebPart.

Code is amended as below. Can you show me a working example code so I can try here?


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FeatureArticles.ascx.cs"
Inherits="CMSWebParts_RealInsurance_Common_LearningCentre_FeatureArticles" %>
<%@ Import Namespace="CMS.WorkflowEngine" %>
<h2>
FeatureArticle</h2>
<table>
<asp:BasicRepeater runat="server" ID="rprFeatureArticle">
<ItemTemplate>
<tr>
<td>
Direct Uploader :
</td>
<td>
<%# IfEmpty(Eval("ArticleImage"), "", GetImage("ArticleImage")) %>
</td>
</tr>
<tr>
<td>
Direct Uploader (resized):
</td>
<td>
<%# IfEmpty(Eval("ArticleImage"), "", GetImage("ArticleImage", 160, 160, 120, Eval("ArticleTitle"))) %>
</td>
</tr>
<tr>
<td>
Image Selection :
</td>
<td>
<%# IfEmpty(GetDocumentUrl("test",""), "", GetImageByUrl(GetDocumentUrl("test","")))%>
</td>
</tr>
<tr>
<td>
Image Selection (resized):
</td>
<td>
<%# IfEmpty(GetDocumentUrl("test",""), "", GetImageByUrl(GetDocumentUrl("test",""), 100, 100, 100, Eval("ArticleTitle")))%>
</td>
</tr>
</ItemTemplate>
</asp:BasicRepeater>
</table>

User avatar
Member
Member
kentico_michal - 10/7/2011 5:38:33 AM
   
RE:Webpart Questions
Hello,

As I said in my previous post, methods from CMSAbstractTransformation can be used only in tranformation. It means that you need to use CMS:CMSRepeater control and its TransformtionName property to specify a transformation you want to use, instead of asp:BasicRepeater.

For example:
<cms:CMSRepeater ID="CMSRepeater1" runat="server" ClassNames="cms.news" OrderBy="NewsReleaseDate DESC" TransformationName="cms.news.preview" SelectedItemTransformationName="cms.news.default"> </cms:CMSRepeater>


This approach works correctly and moreover transformations can be edited directly in the Site manager -> Development -> edit document type -> Transformation.

For more information about CMS:CMSRepeater control, please visit this section of Control's guide:
CMSRepeater getting started

Best regards,
Michal Legen

User avatar
Certified Developer v7
Certified  Developer v7
dion.tsai-adrenalinmedia.com - 10/11/2011 10:14:29 PM
   
RE:Webpart Questions
Thanks for the reply. I guess all the custom webparts that we have developed must use transformation with CMS repeater since all the helper functions (GetDocumentUrl() etc ) are only available in CMSAbstractTransformation.

One silly question here, as in the nested controls example below.
http://www.kentico.com/docs/controls/index.html?cms_listings_and_viewers_using_nested_controls.htm

If I would like to make <h1><%# Eval("DocumentName") %></h1> is clickable where it links the heading page. How to I do that?

User avatar
Member
Member
kentico_michal - 10/12/2011 7:18:36 AM
   
RE:Webpart Questions
Hello,

I am not sure what you mean, but you can create a link to a document as follows:

<a href="<%# GetDocumentUrl() %>"><%# Eval("DocumentName") %></a>


Best regards,
Michal Legen

User avatar
Certified Developer v7
Certified  Developer v7
dion.tsai-adrenalinmedia.com - 10/12/2011 5:57:00 PM
   
RE:Webpart Questions
Hi there,

Thanks for the reply. I tried your code. I got an error.

The name 'GetDocumentUrl' does not exist in the current context.

In the example, since the controls are in the web form, GetDocumentUrl seems not available.

I guess I will have to make a new transformation for CMSRepeater1 and use GetDocumentUrl() in transformation, right?


User avatar
Member
Member
kentico_michal - 10/13/2011 3:40:39 AM
   
RE:Webpart Questions
Hello,

Yes, you are right, you the GetDocumentUrl method as any other transformation metdon can be used only within transformation.

You can also add the definition of the nested control to the transformaton.

Best regards,
Michal Legen