+1-888-365-2779
Try Now
More in this section
Categories
Bloggers
Blogs RSS feed

MetaMaster 2008 - finally released!

by Ivan Osmak
 

Nice title, ehh?

Since everyone seems to be releasing something these days, I thought I’d give it a try on my blog as well. From now on, I’ll be branding all the code samples.  For the time being all the samples will be released under RandomSFCode label (until I come with something more along the web 2.0 lines) and the first control is MetaMaster 2008 (even though it sounds like it could help you lose 20 lbs in 10 days, it won’t. Nevertheless, talk to your physician about it. He may like it.)

So, what is MetaMaster 2008?

MetaMaster 2008 is a control that you can use in conjunction with any ContentView based control (ContentView, BlogPosts, NewsView and EventsView). What MetaMaster 2008 allows you to do is to easily map the values of meta-fields to any property of any control inside of a template. Take a look at the following example:

<cc1:MetaMaster ID="MetaMaster1" runat="server">  
    <Mappings> 
        <cc1:MetaMapping MetaKey="Title" TargetControlId="testLabel"                               TargetProperty="Text" /> 
        <cc1:MetaMapping MetaKey="Author_Picture" TargetControlId="testImage"     
                         TargetProperty="ImageUrl" /> 
        <cc1:MetaMapping MetaKey="Author_Picture" TargetControlId="testImage"    
                         TargetProperty="Tooltip" /> 
    </Mappings> 
</cc1:MetaMaster> 
 

 

All you need to do is place this control in any of the ContentView templates (for now this control will work only in a template for SingleItem mode – for example, for NewsView you can add this control to ListPageDetails.ascx).

So, once you place the MetaMaster control in the template, you can add any number of mappings to it. Each mapping consists of three properties that you need to set:

MetaKey
– the value of which meta-field should be mapped to control’s property
TargetControlId – the id of the control whose property you want to map to meta-field value
TargetProperty – finally, the value of which property you want to set to the value of meta-field

The way standard ContentView control works is following – it reads all the metakeys, tries to find the controls with same ids and then sets the text property of the control to the value of the meta-field. Sometimes, however, you may need two labels to display the value of same meta-field. On other occasions, you may have the URL as a value of meta-field and you want this value to be in ImageUrl or NavigateUrl property, not just text. The common solution to this problem is to overwrite the ContentView control and make your own implementation – and judging by your feedback – you don’t exactly enjoy this. So – that’s how MetaMaster 2008 was born (the slow Thursday in office helped as well).

How to install MetaMaster 2008?

The control comes with full source, so you can modify it or fix it, if needed. Basically, all you need to do is compile the .dll with the references to the dependent projects from your own website (or you can use my .dll if you are running the latest hotfix).

YOU CAN DOWNLOAD THE WHOLE PROJECT FROM HERE.

1. Then take that .dll and copy it to the bin folder of your website.

DO NOT UPLOAD THIS CONTROL THROUGH SITEFINITY PAGE EDITOR.

2. Open the template (in Visual Studio) that represents a template for single item mode of any ContentView control. Here are some examples:

~/Sitefinity/ControlTemplates/News/Modes/ListPageDetails.ascx       ~/Sitefinity/ControlTemplates/Events/Modes/ListPageDetail.ascx         ~/Sitefinity/ControlTemplates/Generic_Content/ContentViewSingleItem.ascx

3. Register the assembly for the control, by adding this line at the top of the template:

<%@ Register Assembly="RandomSFCode.MetaMaster2008"                   
             Namespace="RandomSFCode.MetaMaster2008" 
             TagPrefix="cc1" %> 
 

4. Add the MetaMaster control to the template and start mapping:

<cc1:MetaMaster ID="MetaMaster1" runat="server">  
    <Mappings> 
        <cc1:MetaMapping MetaKey="Title" TargetControlId="testLabel"                               TargetProperty="Text" /> 
        <cc1:MetaMapping MetaKey="Author_Picture" TargetControlId="testImage"    
                         TargetProperty="ImageUrl" /> 
        <cc1:MetaMapping MetaKey="Author_Picture" TargetControlId="testImage"     
                         TargetProperty="Tooltip" /> 
    </Mappings> 
</cc1:MetaMaster> 
 

 

YOU CAN DOWNLOAD THE WHOLE PROJECT FROM HERE.

I’ve done some superficially testing and its working. If you ran in problems leave a comment and I’ll try to address them in timely manner.

   

7 comments

Leave a comment
  1. john Jul 04, 2008
    Thanks for this can i make a quick suggestion about your blog posts like these If you could give a practical example of how we could use this in an everyday use. a "WHY USE THIS" section, i.e. this code will help your pages on the search engines by doing this that and the other...
  2. Ivan Jul 04, 2008
    Hi John, yes I should have made a header "How to use this", but I've forgot. Anyhow, this piece of text explains the reasons: [The way standard ContentView control works is following – it reads all the metakeys, tries to find the controls with same ids and then sets the text property of the control to the value of the meta-field. Sometimes, however, you may need two labels to display the value of same meta-field. On other occasions, you may have the URL as a value of meta-field and you want this value to be in ImageUrl or NavigateUrl property, not just text. The common solution to this problem is to overwrite the ContentView control and make your own implementation – and judging by your feedback – you don’t exactly enjoy this. So – that’s how MetaMaster 2008 was born (the slow Thursday in office helped as well).] - basically, you do not need to overwrite ContentView control if you want to map the "Author_Picture" meta-field value to the ImageUrl property of the "testImage" control. I am sorry I didn't make this cleared.
  3. Seth Jul 11, 2008
    This is brilliant... we had to override just to place a image control and set a metadata field as the src property so this is great news.
  4. SelArom Jul 17, 2008
    this is all kinds of sweet!!! THANK YOU!
  5. Mark Jul 31, 2008
    Like a good doctor, you have taken my pain away! Great solution. Thank you.
  6. GC Nov 10, 2008
    Nice :)
  7. Jochem Aug 11, 2009
    Hey Ivan,

    Is MetaMaster still valid for 3.6sp2 / 3.7 ?

    Regards,

    Jochem

    Leave a comment