Passing custom field value to Transformation of a Widget

joyanta sen asked on August 28, 2018 17:58

Hi, I have created a widget and add a new field in that. Now I need to pass the newly added field value in the macros present in a Transformation which is assigned to the Widget.

Could you please let me know is it possible or not?

Thanks.

Recent Answers


Arun Kumar answered on August 28, 2018 18:04 (last edited on August 28, 2018 18:05)

Hi,

I dont think you can access the widget properties directly in transformation, but you can achieve this by get set webpart properties and then register your webpart as a widget. See this link for help.

1 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on August 29, 2018 04:18 (last edited on August 29, 2018 05:33)

It should be similar to finding web part property from transformation, so let say if you want to get Title, you can do something like this:

<%@ Import Namespace="CMS.PortalEngine.Web.UI" %>
<%=((CMSAbstractWebPart)this.Parent.Parent.Parent).WebPartTitle %>

The idea is to go up in the page controls hierarchy till you find your webpart. You can generalize it, i.e.:

<%@ Import Namespace="CMS.PortalEngine.Web.UI" %>
<script runat="server">
    private static CMSAbstractWebPart GetParentWebpart(System.Web.UI.Control ctrl)
    {
      if (ctrl is CMSAbstractWebPart) return ctrl as CMSAbstractWebPart;
      if (ctrl.Parent == null) return null;
      return GetParentWebpart(ctrl.Parent);
    }
</script>
%>
...
<%=ValidationHelper.GetString(GetParentWebpart(this)?.GetValue("PropertyName"),"")%>

Since every widget is based on an existing web part (widgets essentially lightweight versions of web parts), this script should give you something back. This above will work in ASCX transformation, you probably need to convert Text/XML to ASCX.

P.S. Macro is a different story, although you can try to access directly your property i.e.{%WebPartTitle%} See if works. I know if it works in web part context, but try it in transformation,it might work there as well. If not - convert to ACSX.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.