Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

"Virtual" properties substituting e.g. MainBody on special pages

Vote:
 

A recurring problem with pages typically holding data more than being articles is that functionality of list pages & search result pages, showing the site's "standard" page properties.

Now, if I have pages that do not have these properties at all, what would be the simplest way to make the pages show a "custom" header / text without actually implementing the Header & the MainBody fields ?

What I need is a readonly "MainBody" property that concatinates & formats data from different page properties. How ?

Regards, Bjørge

#36319
Jan 25, 2010 15:41
Vote:
 

Not sure I understand completely.. you wish to check for the Header and MainBody property, if their not available display some other custom content?

#36333
Jan 25, 2010 20:52
Vote:
 

Yes, by design all pages have MainBody and Heading properties. So far so good. What I don't think is a good design "twist", would be letting the search page know the internals of all kinds of pages it may display.

Hence, I would like my "special" page to have some kind of "virtual property" MainBody to render in listings other than the pages specially designed for the custom contents.

With CMS6 I could possibly use a custom property type with settings - to allow for runtime rendering via a template-like property type, like:

Property Name: MainBody

Property type: VirtualProperty

Property Settings: DisplayMask={AUTHORS}<BR /><B>{PUBLISHER}</B>, <I>{YEAR}</I>

Show in Editor: false

...so that this field would output a mix of specified fields with some formatting inbetween.

I like this idea, but I'd rather wait 'til CMS6 upgrade is due...

#36401
Jan 27, 2010 13:44
Vote:
 

Well, it seems like the link is stored in table tblPageSoftlink - so it should be easy to retrieve. I guess ? ? ?

How do I retrieve a collection of pages having linked to a specific page ?

Regards, Bjørge

#36402
Edited, Jan 27, 2010 14:02
Vote:
 

EPiServer.DataAbstraction.SoftLink.LoadReferencing finds links in inline content pointing to a specific page. The links are extracted during indexing so there is a small delay (default 1 minute) until this data surfaces if you don't change the indexing delay in web.config.

#36406
Jan 27, 2010 16:15
Vote:
 

Thanks !

This sounds perfectly fine.

Is there a simple way to extract a set of pages being referenced, or do I have to do this the "hard way" ?

#36410
Jan 27, 2010 17:07
Vote:
 

SoftLink.Load loads the what pages are being referenced.

#36412
Jan 27, 2010 17:52
Vote:
 

Something went wrong with this thread, obviously, it was mixed with my other thread:

 

Property / content type for person-links

Well, the person-linking is now thoroughly explained. Jolly good.

Remaining is the "Virtual property" question, I'm really keen on hearing how others have solved this...

Anny suggestions ?

#36435
Jan 28, 2010 11:00
Vote:
 

Have you seen this?

http://blogs.interakting.co.uk/post/Property-Data-Injection-in-EPiServer.aspx

 

#36436
Jan 28, 2010 11:19
Vote:
 

Yes, this was interesting !

I went down another route, though, I created a custom property type that looks for [PropertyName] and substitutes the named property with the actual property value found on the page. Example:

First name: [FirstName]<br>Last name: [Lastname]

....would render as:

First name: Bjørge

last name: Sæther

...and so far, this kind of works. On my development server. However, I can't get it to work on our web server.

The custom property type installs nice, I can get to define a property of the type in a page type, but when it is to be displayed, it simply displays the contents apparently not calling my overridden CreateDefaultFields().

Any ideas, anyone ?

Source code:

public class stringUtils : Object
    {
        public static Boolean extractBetween(ref String s, String LeftD, String RightD, ref int index, out String Contents, Boolean doDelete, Boolean doDeleteDelimiters)
        {
            int indexR;
            int lenDelimL = LeftD.Length;
            int lenDelimR = RightD.Length;
            index = s.IndexOf(LeftD, index);
            indexR = s.IndexOf(RightD, index + 1);
            if ((index >= 0) && (indexR >= 0))
            {
                Contents = s.Substring(index + lenDelimL, indexR - (index + lenDelimL));
                if (doDeleteDelimiters)
                {
                    s = s.Remove(index, (indexR - index) + lenDelimR);
                }
                else if (doDelete)
                {
                    s = s.Remove(index + lenDelimL, Contents.Length);
                    index += 1;
                }
                return true;
            }
            Contents = "";
            return false;
        }
    }

    public class PropertyProxyFieldsControl : PropertyStringControl
    {
        private String _replaceFields()
        {
            String propName = "";
            String propValue = "";
            int index = 0;
            String s = this.PropertyData.ToString();
            try
            {
                while (stringUtils.extractBetween(ref s, "[", "]", ref index, out propName, true, true))
                {
                    propValue = this.PropertyData.Parent[propName].ToString();
                    s = s.Insert(index, propValue);
                }
            }
            catch
            {
                s = " (Error: property [" + propName + "] not found)";
                return s;
            }
            return s;
        }

        public override void CreateDefaultControls()
        {
            Panel target = new Panel();
            Literal child = new Literal();
            child.Text = this._replaceFields();
            target.Controls.Add(child);
            base.CopyWebAttributes(target);
            this.Controls.Add(target);
        }
        
    }

    [Serializable]
    [PageDefinitionTypePlugIn]
    public class PropertyProxyFields : EPiServer.Core.PropertyString
    {
        public override IPropertyControl CreatePropertyControl()
        {
            return new PropertyProxyFieldsControl();
        }

    }
#36824
Feb 11, 2010 15:15
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.