PropertyAdapters updated

by: Anders Hattestad

Have added some cool functionality to Hattis.PageAdapters

If you use EPiServer:Property to show your attribute you can try out these 4 new Attribute tags:

  • Format
  • Remove
  • Text
  • Translate

EPiServer out of the box will render the following:

<EPiServer:Property PropertyName="PageName"  ID="Property1"  DisplayMissingMessage="false" EnableViewState="false" runat="server" />
<EPiServer:Property PropertyName="MainBody"  DisplayMissingMessage="false" EnableViewState="false" runat="server" />

as this html code:

image

I have added some logic in CreateDefaultControls that checks additional attributes to the EPiServer:Property tag

Format

If the control have ITextControl or  Hyperlink the text will be inserted in the format string provided.

<EPiServer:Property Format="<h1>{0}</h1>" PropertyName="PageName"  ID="Property1"  DisplayMissingMessage="false" EnableViewState="false" runat="server" />
<EPiServer:Property PropertyName="MainBody"  DisplayMissingMessage="false" EnableViewState="false" runat="server" />

 

image

Remove

If you add Remove=true then the outer control will be used, and only the text will be displayed.

image

This is some of the same concept Itera.Property uses, but there is no need to change the web control.

Text and Translate

If you add a Text attribute and/or a Translate attribute that value will be {1} and can be used like this

 

<EPiServer:Property 
Text="default text:" Format="<h1>{1}{0}</h1>" Remove="true" PropertyName="PageName" ID="Property1" DisplayMissingMessage="false" EnableViewState="false" runat="server" /> <EPiServer:Property Remove="true" PropertyName="MainBody" DisplayMissingMessage="false" EnableViewState="false" runat="server" /> <EPiServer:Property ID="Property2" PropertyName="PageLink" Format="{1} : {0}" Text="Read more" Translate="/readmore" runat="server" />

Will render like this

image

Dope

These techniques work even with dope, but the extra format tags will not be displayed.

image

The code

the main part of the actully code that does these tricks is something like this.

public override void CreateDefaultControls()
{
    base.CreateDefaultControls();
    AddDisplayHacks();

}
public void AddDisplayHacks()
{
    if (EditControl != null)
    {
        Control use = EditControl;
        if (use is Panel && use.Controls.Count>0)
            use = EditControl.Controls[0];
        if (use is ITextControl)
            (use as ITextControl).Text = GetNewText((use as ITextControl).Text);
        else if (use is HyperLink)
            (use as HyperLink).Text = GetNewText((use as HyperLink).Text);
        if (EditControl is WebControl)
        {
            (EditControl as WebControl).Attributes.Remove("Format");
            (EditControl as WebControl).Attributes.Remove("Text");
            (EditControl as WebControl).Attributes.Remove("Translate");
        }
    }
}
string GetNewText(string text)
{
    string text2 = GetTranslate(GetText(""));
    string format = GetFormat("{0}");
    string result = string.Format(format, text, text2); ;
    if (string.IsNullOrEmpty(text))
        EditControl.Visible = false;
    else
    {
        string removeTag = GetAttribute("Remove", "false");
        if (removeTag.ToLower() == "true")
        {
            Literal l = new Literal();
            l.Text = result;
            this.PropertyDataControl.Controls.Add(l);
            this.PropertyDataControl.Controls[0].Visible = false;
        }
    }
    return result;
}

 

Download

Is available on epicode

or

Direct download here

16 April 2009


Comments

  1. Nice! No need to change from the EPiServer Property control, just change it in-place.
  2. Cool! I guess the same way could be used to set default values to EnableViewState and DisplayErrorMessage.
  3. Hi Anders, How can we implement this into our project/Episerver CMS6? Thanks
  4. This code should work on cms6
  5. It's not working. Some dlls are referencing to 5.2 Thanks
  6. Hi Anders, I referenced the porpertyadapter dll. I edited the browser file such that it points to that class file. But at runtime it is specifying configuration error. Please let me know if i need to change anything else..
  7. adapter controlType="EPiServer.Web.PropertyControls.PropertyXhtmlStringControl" adapterType="CreditSites.Templates.CommonFiles.Utilities.MyPropertyXhtmlStringAdapter"
  8. Hello Anders, Finally i was able to use your dll's. But there is one problem which we are facing. If we have an xhtml property & inside that we have a dynamic content placed, then the format,remove feature is not working. Can you please let us know how we can achieve this? Thanks Rachappa
  9. Hi When I said that the code was working in CMS 6, I was thinking about the code, not the dll. But to your problem. Start debuger, then make a break point in AddDisplayHacks, and find out what kind of type the new editor makes for an output.
  10. Hi Thanks for the reply. The edit control it is showing as Panel and the binding container has

    {DynamicContent:PiacTitle}. When it gets the newtext it is trimming out the span attribute which is placed inside the P tag.

  11. BindingContainer p span classid="b30218a7-77fc-43dd-a844-81935aa9b35e" dynamicclass="PiacTitle" state="000939" hash="tlHzi1kzO7VZNnyzg5mD6NRkhCnhjsf9dkI/vxIEdhI=" disabled="disabled" contentEditable="false" class="dynamiccontent"{DynamicContent:PiacTitle} span p
  12. In the panel there are 3 controls, 2 are literal and one is an ascx contorl. System.Web.UI.WebControls.Literal ASP.templates_commonfiles_controls_piactitle_ascx System.Web.UI.WebControls.Literal Thanks
Post a comment    
User verification Image for user verification  
EPiTrace logger