Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > How to use new webpart property field value inside transformation View modes: 
User avatar
Member
Member
gliker-inorbital - 9/30/2011 9:21:50 AM
   
How to use new webpart property field value inside transformation
Hi,

I created new webpart property with attribute value "NewsSettingsTitle". What is the easiest way to use this value inside transformation?

Thanks

User avatar
Certified Developer 9
Certified Developer 9
charbf - 9/30/2011 10:10:22 PM
   
RE:How to use new webpart property field value inside transformation
Hi,

like this.

<%# this.NewsSettingsTitle %>

User avatar
Member
Member
Giuliano - 10/3/2011 9:15:08 AM
   
RE:How to use new webpart property field value inside transformation
Hi charbf,

I already tried that and something similar but unfortunately I'm getting this error.
[CMSDataProperties.LoadTransformation]: http://server/CMSTransformations/98b3398b-cbdf-4abe-9578-66c4fddd6748/csmls/news/sidebar.ascx(3): error CS1061: 'ASP.cmstransformations_98b3398b_cbdf_4abe_9578_66c4fddd6748_csmls_news_sidebar_ascx' does not contain a definition for 'EnglishTitle' and no extension method 'EnglishTitle' accepting a first argument of type 'ASP.cmstransformations_98b3398b_cbdf_4abe_9578_66c4fddd6748_csmls_news_sidebar_ascx' could be found (are you missing a using directive or an assembly reference?)

I have property 'EnglishTitle' with some default value, as you can see here:

http://prntscr.com/3baja

And this is my transformation:
<%# this.EnglishTitle %>

<div class="newsItem">

<div class="date">
<%# GetDateTime("NewsDate", "MMMM dd, yyyy") %>
</div>

<div class="newsItemText">
<%# Eval("NewsTitle") %>
</div>

<a class="readMore" href="<%# GetDocumentUrl() %>">Read more</a>

</div> <!-- newsItem -->

I'm not sure what I'm doing wrong here. Any help will be appreciated.

User avatar
Certified Developer v7
Certified  Developer v7
ankur.bathla-hotmail - 10/12/2011 1:48:35 PM
   
RE:How to use new webpart property field value inside transformation
Hi Giuliano,

You need to use code below to get the webpart property field value in your transformation.

<%@ Register TagPrefix="cc2" Namespace="CMS.PortalControls" Assembly="CMS.PortalControls" %>
<script runat="server">
public CMSAbstractWebPart FindWebpart(Control o)
{
if (o is CMSAbstractWebPart)
{
return o as CMSAbstractWebPart;
}
else
{
if (o.Parent != null)
{
return FindWebpart(o.Parent);
}
else
{
return null;
}
}
}

public string GetWebPartproperty()
{
CMSAbstractWebPart currentWebpart = FindWebpart(this);

if (currentWebpart != null)
{
return ValidationHelper.GetString(currentWebpart.GetValue("Webpart property name"), "");
}
else
{
return null;
}
}
</script>

And you can call this as GetWebPartproperty() to get field value.