Forums

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): Developing with Sitefinity > Adding Thumbnails to blog

Adding Thumbnails to blog

  • Scott Williams avatar

    Posted on Nov 11, 2009 (permalink)

    Hi I know that you can display thumbnails along side news but is there anyway that I can do this with the Blog control? There are a number of features I want to use within blog but I also need to include thumbnails. Thanks
     

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Nov 11, 2009 (permalink)

    Hi Scott Williams,

    It is possible. Below are the steps that you should follow:

    1. Map external templates for content item edit  and content item new - PostEdit.ascx and PostNew.ascx.
    2. Create a new metakey for Blogs provider called Thumbnail
    3. Add thumbnail selector inside ContentMetaFields control.

    <li class="selector">
        <asp:Label ID="Label2" AssociatedControlID="Thumbnail" runat="server"><asp:Literal ID="Literal14" runat="server" Text="<%$Resources:Thumbnail %>"></asp:Literal> <em id="ThumbnailLabel" runat="server"></em></asp:Label>
        <asp:TextBox ID="Thumbnail" Text="" runat="server" MaxLength="250"></asp:TextBox>
        <sfLib:ButtonSelector WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ImageEditorDialog.aspx" ItemTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/Dialogs/ButtonSelector.ascx" AssociatedControls="Thumbnail" runat="server" cssclass="pickerWrapper" ButtonText="<%$Resources:Select%>" />
        <p class="example">
       <asp:Literal ID="Literal15" runat="server" Text="<%$Resources:ThumbnailNote %>"></asp:Literal>
       </p>
    </li>

    4. Create a custom control that derives from BlogPosts.
    5. Override ItemListTemplatePath and SingleItemTemplatePath properties and set you templates.
    6. Override SetItemMetaData method , get the thumbnail metadata for the contentItem parameter - if there is an image resolve the value of the field and show the image.
    7. Make sure that you have registered a control ( for instance Image) in your public templates - ListPageMaster and ListPageDetail that will show the thumbnail

    Sample code:

    public class CustomBlogPosts : BlogPosts
    {
     
     
        public override string ItemListTemplatePath
        {
            get
            {
                return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageMaster.ascx";
            }
        }
     
        public override string SingleItemTemplatePath
        {
            get
            {
                return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageDetail.ascx";
            }
        }
     
        protected override void SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)
        {
            base.SetItemMetadata(itemContainer, contentItem);
     
            Image img = (Image)itemContainer.FindControl("Image1");
            string thumb= (string)contentItem.GetMetaData("Thumbnail");
            
              ....
                  ....
              // TODO - SET IMAGE, RESOLVE URL
        }
     
     
     
    }


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

    Reply

  • Joel Housman avatar

    Posted on May 18, 2010 (permalink)

    Ivan,

    Could you elaborate a little more on this process? I do not fully understand your instructions.

    1. How does one go about mapping external templates for 'content item edit' and 'content item new'. I've read documentation on mapping external templates from the help files and other forum posts, but it is not clear.

    2. How do you create a new metakey for Blogs provider? Where do you do this at? Which file? Where is that file located. It is very helpful to customers to tell us all of these things rather than assuming we already know these things.

    3. Where is ContentMetaFields control?

    4. Create a custom control that derives from derives from BlogPosts? Where? How?

    I'll just stop here. But suffice it to say, I too need to add thumbnails to blogs. I found this documentation here: http://www.sitefinity.com/sf3/faq.html#87 Which makes perfect sense to me and I started doing until i realized that it was for Sitefinity 3.2. When I tried to figure it out how to do it for Sitefinity 3.7 I found that you had made this process 100x more complicated and your documentation, unlike for 3.2, doesn't speak to adding custom fields to blogs. It gives an example for the news modile about a field in which I know nothing about. It is very confusing.

    Reply

  • Jay Mehta avatar

    Posted on May 18, 2010 (permalink)

    Hi Ivan,

    I am planning to achieve the same thing, thumbnail functionality in Blogs module, but the steps are not clear to me either, tried mapping the external template, but could not find some of the files mentioned (for eg. ContentMetaFields control).


    Thank you,
    Jay Mehta.

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on May 18, 2010 (permalink)

    Hi Jay Mehta,

    • Mapping templates - How to map a template
    • Adding metafields -  UserManual, section - Adding Custom Fields
    • ContentMetaFields controls is inside the template. This control persists and retrieves the data for the metakeys dynamically, so you should not do this manually.
    • Here is a forum post that shows how to create a custom control that inherits from BlogPosts - blog-posts-control

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

    Reply

  • Jay Mehta avatar

    Posted on May 18, 2010 (permalink)

    Hi Ivan,

    Thank you for the quick reply, that helps. Can you please help or elaborate more on Steps 6 and 7.

    Thank you,
    Jay Mehta.

    Reply

  • Jay Mehta avatar

    Posted on May 19, 2010 (permalink)

    HI Ivan,

    I followed till step 3 and when I try to visit the Blog Edit page I receive the following error.
    Also, could you please help on further steps.

    Thank you,
    Jay Mehta.
    Attached files

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on May 19, 2010 (permalink)

    Hi Jay Mehta,

    The error is thrown, because the resource key you use is not presented in the resx file for this template. Please add the resource key or resx file in case it is missing from App_LocalResources folder.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

    Reply

  • Jay Mehta avatar

    Posted on May 19, 2010 (permalink)

    Thanks Ivan, I was able to resolve that issue, forgot to update the blog.

    I am able to upload thumbnail for a blog post, but how can I display it on the client end?
    What modifications I need to make or further steps I need to take. 

    Thank you,
    Jay Mehta.

    Reply

  • Jay Mehta avatar

    Posted on May 21, 2010 (permalink)

    Hi Ivan,

    I was able to cover all the steps you mentioned, but still it did not display the thumbnail. Can you guide on what could be wrong.

    Here are the steps I did and the code snippet:
    1: Mapped the external templates
    2: Created Metakey for "Blogs.Thumbnail"
    3: Added the thumbnail selector code
    4: Created a class file with following code in the App_code folder
    using System;
    using System.Data;
    using System.Collections.Generic;
    using System.Linq;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Collections;
    using System.ComponentModel;
    using Telerik.Cms.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Telerik.Blogs.WebControls;
    using Telerik.Cms.Engine;
    using Telerik.Framework.Web.Design;
    using Telerik.Lists.PersistentObjects;
      
    namespace Telerik.Blogs.WebControls
    {
        public class CustomBlogPosts : BlogPosts
        {
             
    public override string SingleItemTemplatePath
    {
     get
     {
        object obj = this.ViewState["SingleItemTemplatePath"];
        if (obj != null)
            return (string)obj;
        // otherwise return default path of the SingleItem Template. This should
        // be the path of the new template we have created
        return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageDetail.ascx";
             }
     set
     {
        this.ViewState["SingleItemTemplatePath"] = value;
     }
        }
      
     
        public override string ItemListTemplatePath
    {
     get
     {
        object obj = this.ViewState["ItemListTemplatePath"];
        if (obj != null)
           return (string)obj;
        // otherwise return default path of the ItemList Template. This should 
        // be the path of the new template we have created
                return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageMaster.ascx";
             }
     set
     {
        this.ViewState["ItemListTemplatePath"] = value;
     }
        }
     
     
    protected override void SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)
        {
            base.SetItemMetadata(itemContainer, contentItem);
      
            Image img = (Image)itemContainer.FindControl("Image1");
            string thumb= (string)contentItem.GetMetaData("Thumbnail");
     
                if (img != null)
                {
                     
            img.ImageUrl = thumb;
            img.AlternateText = "This is from the class file";
                }
         
            }
        }
    }

    5: Registered this class in the web.config
    6: Added the Image control in the ListPageMaster and ListPageDetails
    <p class="sf_newsThumbnail"><asp:Image ID="Image1" runat="server" /></p>

    Thank you,
    Jay Mehta.

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on May 24, 2010 (permalink)

    Hi Jay Mehta,

    If you use ButtonSelector control, it returns a Guid, so you need to resolve the dynamic url. You should also check whether thumb is String.Empty before setting any value to img.ImageUrl.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

    Reply

  • Jay Mehta avatar

    Posted on May 25, 2010 (permalink)

    Thanks Ivan,

    I added the logic for the url resolve, but still it is not displaying anything.
    Here is the code in the class file

    using System;
    using System.Data;
    using System.Collections.Generic;
    using System.Linq;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Collections;
    using System.ComponentModel;
    using Telerik.Cms.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Telerik.Blogs.WebControls;
    using Telerik.Cms.Engine;
    using Telerik.Framework.Web.Design;
    using Telerik.Lists.PersistentObjects;
      
    namespace Telerik.Blogs.WebControls
    {
        public class CustomBlogPosts : BlogPosts
        {
             
    public override string SingleItemTemplatePath
    {
     get
     {
        object obj = this.ViewState["SingleItemTemplatePath"];
        if (obj != null)
            return (string)obj;
        // otherwise return default path of the SingleItem Template. This should
        // be the path of the new template we have created
        return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageDetail.ascx";
             }
     set
     {
        this.ViewState["SingleItemTemplatePath"] = value;
     }
        }
      
     
        public override string ItemListTemplatePath
    {
     get
     {
        object obj = this.ViewState["ItemListTemplatePath"];
        if (obj != null)
           return (string)obj;
        // otherwise return default path of the ItemList Template. This should 
        // be the path of the new template we have created
                return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageMaster.ascx";
             }
     set
     {
        this.ViewState["ItemListTemplatePath"] = value;
     }
        }
     
     
    private string GetItemUrl(string val)
        {
            if (val.StartsWith("~/"))
                return this.ResolveUrl(val);
      
            if (val.StartsWith("["))
            {
                int idx = val.IndexOf("]");
                string provider = val.Substring(1, idx - 1);
                string strId = val.Substring(idx + 1);
                Guid id = new Guid(strId);
      
                if (ContentManager.Providers.ContainsKey(provider))
                {
                    IContent cnt = ContentManager.Providers[provider].GetContent(id);
                    if (cnt != null)
                        return VirtualPathUtility.ToAbsolute(cnt.UrlWithExtension, this.Context.Request.ApplicationPath);
                }
            }
            return val.ToString();
        }  
     
     
    protected override void SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)
        {
            base.SetItemMetadata(itemContainer, contentItem);
      
            Image img = (Image)itemContainer.FindControl("Image1");
             
                if (img != null)
                {
                     
            string thumb= GetItemUrl((string)contentItem.GetMetaData("Thumbnail"));
     
            img.ImageUrl = thumb;
            img.AlternateText = "This is from the class file";
                }
         
            }
        }
    }

    I also tried commenting the Image url and just displaying AlternateText, but did not display that. I feel it is not reaching this part of the code.

    Thank you,
    Jay Mehta.

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on May 26, 2010 (permalink)

    Hello Jay Mehta,

    If the image is null in your code then neither thumb not AlternateText will be set. Make sure that the path the your image has been resolved.

    The code below works fine at my end


    protected override void SetItemMetadata(Control itemContainer, IContent contentItem)
       {
                base.SetItemMetadata(itemContainer, contentItem);
                   string key = "Thumbnail";
                   Control ctrl = base.FindContentViewControl(key , itemContainer);
                   string imageUrl = (string)contentItem.GetMetaData(key);
                   if (!String.IsNullOrEmpty(imageUrl))
                   {
                       ((System.Web.UI.WebControls.Image)ctrl).ImageUrl = this.GetItemUrl(imageUrl, false);
                   }
      
       }


    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

    Reply

  • Jay Mehta avatar

    Posted on May 26, 2010 (permalink)

    Thanks Ivan,

    I tried your code and also tried just accessing the Title literal from the ListPageDetail.ascx file and changing the text for it, but not sure why it is not making any changing on the front side.

    Here is the change I made in the code that you sent

    protected override void SetItemMetadata(Control itemContainer, IContent contentItem)
       {
                base.SetItemMetadata(itemContainer, contentItem);
                   string key = "Thumbnail";
                   Control ctrl = base.FindContentViewControl(key , itemContainer);
    Literal ctrl1 = itemContainer.FindControl("Title") as Literal;
    ctrl1.Text = "Hi";
                   string imageUrl = (string)contentItem.GetMetaData(key);
                   if (!String.IsNullOrEmpty(imageUrl))
                   {
                       ((System.Web.UI.WebControls.Image)ctrl).ImageUrl = this.GetItemUrl(imageUrl, false);
                   }
       
       }

    Can you please let me know, what I am missing.
    Is there a way, I can find if the control is reaching in this method?

    Thank you,
    Jay Mehta.

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on May 27, 2010 (permalink)

    Hello Jay Mehta,

    Please use the code below.


    public class BlogPostsCustomControl : BlogPosts
    {
        public BlogPostsCustomControl()
        {
        }
        public override string SingleItemTemplatePath
        {
            get
            {
                return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageDetail.ascx";
                
            }
     
        }
     
        public override string ItemListTemplatePath
        {
            get
            {
                return "~/Sitefinity/Admin/ControlTemplates/Blogs/Modes/ListPageMaster.ascx";
            }
        }
     
     
        protected override void SetItemMetadata(Control itemContainer, IContent contentItem)
        {
            base.SetItemMetadata(itemContainer, contentItem);
            foreach (IMetaInfo info in Manager.MetaKeys.Values)
            {
                Control ctrl = base.FindContentViewControl(info.Key, itemContainer);
                if ((ctrl != null)
                     && (ctrl is System.Web.UI.WebControls.Image)
                     && (info.ValueType == MetaValueTypes.ShortText))
                {
                    string imageUrl = (string)contentItem.GetMetaData(info.Key);
                    if (!String.IsNullOrEmpty(imageUrl))
                    {
                        ((System.Web.UI.WebControls.Image)ctrl).ImageUrl = this.GetItemUrl(imageUrl, false);
                    }
                    else
                    {
                        ((System.Web.UI.WebControls.Image)ctrl).Visible = false;
                    }
                }
            }
        }
     
     
        private string GetItemUrl(string val, bool resolveAsAbsoluteUrl)
        {
            if (val.StartsWith("~/"))
                return this.ResolveUrl(val);
     
            if (val.StartsWith("["))
            {
                int idx = val.IndexOf("]");
                string provider = val.Substring(1, idx - 1);
                string strId = val.Substring(idx + 1);
                Guid id = new Guid(strId);
     
                if (ContentManager.Providers.ContainsKey(provider))
                {
                    IContent cnt = ContentManager.Providers[provider].GetContent(id);
                    if (cnt != null)
                        return VirtualPathUtility.ToAbsolute(cnt.UrlWithExtension, this.Context.Request.ApplicationPath);
                }
                else
                {
                    string url = CmsHelper.GetPageUrl(id, this.Context);
                    if (!string.IsNullOrEmpty(url))
                    {
                        return url;
                    }
                }
                return String.Concat("Item not found: [", provider, "]", id);
            }
            return val.ToString();
        }
    }



    You will find a sample video that shows how the image is correctly displayed and mapped

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Attached files

    Reply

  • Jay Mehta avatar

    Posted on May 27, 2010 (permalink)

    Thanks Ivan.

    I get error on the CmsHelper.GetPageUrl........is the GetPageUrl custom method?


    Thank you,
    Jay Mehta.
    Attached files

    Reply

  • Radoslav Georgiev Radoslav Georgiev admin's avatar

    Posted on May 27, 2010 (permalink)

    Hi Jay Mehta,

    Add a reference to Telerik.Cms.Web in your control:
    using Telerik.Cms.Web;

    Also check your Sitefinity version. In older versions(prior to Sitefinity 3.7 the method call is with only one parameter - the page ID.

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

    Reply

  • Jay Mehta avatar

    Posted on May 27, 2010 (permalink)

    Thanks Ivan for the quick reply.

    I had added that reference.

    The version we are using is 3.6, and thats why I think the method does not work. But if it is expecting only 1 parameter, it should throw that error rather then method not found.

    Do I need to create that method?

    Thank you,
    Jay Mehta.

    Reply

  • Jay Mehta avatar

    Posted on Jun 14, 2010 (permalink)

    Hi,

    Any updates on this? I still was not able to achieve the functionality.

    Thank you,
    Jay Mehta.

    Reply

  • Radoslav Georgiev Radoslav Georgiev admin's avatar

    Posted on Jun 15, 2010 (permalink)

    Hello Jay Mehta,

    Try calling the method only with ID arguement.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

    Reply

  • aaron avatar

    Posted on Jun 29, 2010 (permalink)

    Hello Radoslav Georgiev
     
    I have been trying too add an image to the blog post using the technique used in this post.  I can upload the image fine but the thumbnail is never displayed for the blogs posts.  I think I am stuck at registering the app_code class in the web.config.  I am unsure where to add this?

    Many thanks

    Reply

  • Siddesh Kapadi Master avatar

    Posted on Jun 29, 2010 (permalink)

    hey Aaron,
    Add the same in the toolboxControls section. Something similar to the below would already be available.

    <add name="Video" section="Most popular" type="Telerik.Libraries.WebControls.Video, Telerik.Libraries" description="Video content control"/>

    Regards,
    Siddesh Kapadi

    Reply

  • Posted on Nov 17, 2010 (permalink)

    Hi,

    I would just like to follow up on the last questions asked about finishing this project off by adding it to the web.config. I've been trying unsuccessfully to get the code to load through the toolbox, I constantly receive an error along the lines of: Error Loading Control.

    using System;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using Telerik.Blogs.WebControls;
    using Telerik.Cms.Engine;
    using Telerik.Cms.Web;

    using System;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using Telerik.Blogs.WebControls;
    using Telerik.Cms.Engine;
    using Telerik.Cms.Web;
     
    namespace Telerik.Blogs.WebControls
    {
        public class CustomBlog : BlogPosts
        {
            public CustomBlog()
            {
            }
            public override string SingleItemTemplatePath
            {
                get
                {
                    return "~/Sitefinity/ControlTemplates/Blogs/Modes/ListPageDetail.ascx";
     
                }
     
            }
            ...
    }

    And then I try and reference it as follows in the web.config

    <toolboxControls>
            <clear />
    <add name="Custom Blog" section="Most popular" type="Telerik.Blogs.WebControls.CustomBlog, Telerik.Blogs" description="Custom Blog Module" />:
    </toolboxControls>

    I would really appreciate a pointer into the right direction. Thanks.

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Nov 17, 2010 (permalink)

    Hi Trevor,

    The assembly you use Telerik.Blogs is not correct

    type="Telerik.Blogs.WebControls.CustomBlog, Telerik.Blogs"

    Your class library should not be called Telerik.Blogs.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Posted on Nov 17, 2010 (permalink)

    Hi Ivan,

    Thank you for your reply. Could you please help me with an example of how the web.config line should look as well as the code it references.

    At the moment I've tried to change it to the following:

    namespace CustomModule
    {
        public class CustomBlog : BlogPosts
        {
            public CustomBlog()
            {
            }
            public override string SingleItemTemplatePath
            {
                get
                {
                    return "~/Sitefinity/ControlTemplates/Blogs/Modes/ListPageDetail.ascx";
     
                }
    ...
    }

    And then
    <add name="Custom Blog" section="Most popular" type="CustomModule.CustomBlog, CustomModule"
              description="Custom Blog." />

    This Code is directly inside the App_Code directory.

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Nov 17, 2010 (permalink)

    Hi Trevor,

    The parameters of the toolbox control are

    name - control name
    section - section where you want to see your control in the Toolbox
    type - control type in format Namespace, AssemblyName
    description - short description about the control

    sample


    <add name="some name" section="Custom"  type="CustomModule.CustomBlog ,CustomModule"/>

    If your class library is  called CustomModule there this is what you have to add as an assembly name(highlighted with yellow).

    When you are inheriting from ContentView control you should override both template paths - for list mode and details mode as my code shows.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Posted on Nov 17, 2010 (permalink)

    Hi Ivan,

    Thank you for your very detailed response, it really helped clear things up. I am just still puzzling how I should set the Type when I'm using code from the App_Code.

    I've successfully got it running from a Class Project I created and then referencing that class file. But what do I do if I use App_Code

    example: <add name="some name" section="Custom"  type="CustomModule.CustomBlog ,???"/>

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Nov 17, 2010 (permalink)

    Hi Trevor,

    Use

    type="MyType, App_Code"

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Posted on Nov 17, 2010 (permalink)

    Thanks Ivan, you're the best! That's exactly what I needed!

    Reply

  • Iain avatar

    Posted on Jan 31, 2011 (permalink)

    Could you provide an example of how to edit the resx file?

    Or point me in the right direction...?

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Jan 31, 2011 (permalink)

    Hi,

    Which resx file you  are referring to?

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Iain avatar

    Posted on Jan 31, 2011 (permalink)

    The PostNew.ascx.resx in the admin/controltemplates/blogs/app_localresources

    I got to the point Jay Mehta did with the parse error, it was mentioned to edit the resx file, which code should be edited using this threads examples to add a thumbnail image.

    Also does the IIS need to be restarted at any point?

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Jan 31, 2011 (permalink)

    Hello aaron,

    You can edit the files in Visual Studio without problems. This is a standard ASP.NET resx file. IIS restart is not required.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Ravikant Gaud avatar

    Posted on Jan 31, 2011 (permalink)

    Hi,

    I wanted to display a thumbnail image in my blog post, I gone through this post

    Added a meta key in web.config with the name "thumbnail".
    created a .cs file in App_code folder and add below codes in it

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Blogs.WebControls;
    using Telerik.Cms.Engine;
    using System.Web.UI;
    using Telerik.Cms.Web;
    using Telerik.Web;
    using System.Web.UI.WebControls;
     
     
    namespace Telerik.Blogs.WebControls
    {
        public class CustomBlogPost : BlogPosts
        {
            public CustomBlogPost()
            {
     
            }
     
            public override string ItemListTemplatePath
            {
                get
                {
                    return "~/Sitefinity/ControlTemplates/Blogs/ContentViewItemList.ascx";
                }
            }
     
            public override string SingleItemTemplatePath
            {
                get
                {
                    return "~/Sitefinity/ControlTemplates/Blogs/ContentViewSingleItem.ascx";
                }
            }
     
            protected override void SetItemMetadata(Control itemContainer, IContent contentItem)
            {
                base.SetItemMetadata(itemContainer, contentItem);
                foreach (IMetaInfo info in Manager.MetaKeys.Values)
                {
                    Control ctrl = base.FindContentViewControl(info.Key, itemContainer);
                    if ((ctrl != null)
                         && (ctrl is System.Web.UI.WebControls.Image)
                         && (info.ValueType == MetaValueTypes.ShortText))
                    {
                        string imageUrl = (string)contentItem.GetMetaData(info.Key);
                        if (!String.IsNullOrEmpty(imageUrl))
                        {
                            ((System.Web.UI.WebControls.Image)ctrl).ImageUrl = this.GetItemUrl(imageUrl, false);
                        }
                        else
                        {
                            ((System.Web.UI.WebControls.Image)ctrl).Visible = false;
                        }
                    }
                }
            }
     
            private string GetItemUrl(string val, bool resolveAsAbsoluteUrl)
            {
                if (val.StartsWith("~/"))
                    return this.ResolveUrl(val);
     
                if (val.StartsWith("["))
                {
                    int idx = val.IndexOf("]");
                    string provider = val.Substring(1, idx - 1);
                    string strId = val.Substring(idx + 1);
                    Guid id = new Guid(strId);
     
                    if (ContentManager.Providers.ContainsKey(provider))
                    {
                        IContent cnt = ContentManager.Providers[provider].GetContent(id);
                        if (cnt != null)
                            return VirtualPathUtility.ToAbsolute(cnt.UrlWithExtension, this.Context.Request.ApplicationPath);
                    }
                    else
                    {
                        string url = CmsHelper.GetPageUrl(id);
                        if (!string.IsNullOrEmpty(url))
                        {
                            return url;
                        }
                    }
                    return String.Concat("Item not found: [", provider, "]", id);
                }
                return val.ToString();
            }
     
        }
     
    }

    but I not able to display a Image in front end.
    Can you please let me know, what I am missing.

    regards,
    ravikant

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Jan 31, 2011 (permalink)

    Hello aaron,

    Please check what is returned by GetItemUrl and what parameters you pass to it.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Iain avatar

    Posted on Jan 31, 2011 (permalink)

    Hi Ivan,

    Ive added the item Thumbnail to the resx file and added the following code to the ContentMetaFields tag in Blogs/PostNew.aspx

    <asp:Label ID="Label2" AssociatedControlID="Thumbnail" runat="server"><asp:Literal ID="Literal14" runat="server" Text="<%$Resources:Thumbnail %>"></asp:Literal> <em id="ThumbnailLabel" runat="server"></em></asp:Label>
        <asp:TextBox ID="Thumbnail" Text="" runat="server" MaxLength="250"></asp:TextBox>
        <sfLib:ButtonSelector WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ImageEditorDialog.aspx" ItemTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/Dialogs/ButtonSelector.ascx" AssociatedControls="Thumbnail" runat="server" cssclass="pickerWrapper" ButtonText="<%$Resources:Select%>" />
        <p class="example">
       <asp:Literal ID="Literal15" runat="server" Text="<%$Resources:ThumbnailNote %>"></asp:Literal>
       </p>

     and Im now receiving this error:


    Parser Error Message: Unknown server tag 'sfLib:ButtonSelector'.

    Source Error:

    Line 264:                    <asp:Label ID="Label3" AssociatedControlID="Thumbnail" runat="server"><asp:Literal ID="Literal14" runat="server" Text="<%$Resources:Thumbnail %>"></asp:Literal> <em id="ThumbnailLabel" runat="server"></em></asp:Label>
    Line 265:    <asp:TextBox ID="Thumbnail" Text="" runat="server" MaxLength="250"></asp:TextBox>
    Line 266:    <sfLib:ButtonSelector WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ImageEditorDialog.aspx" ItemTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/Dialogs/ButtonSelector.ascx" AssociatedControls="Thumbnail" runat="server" cssclass="pickerWrapper" ButtonText="<%$Resources:Select%>" />
    Line 267:    <p class="example">
    Line 268:   <asp:Literal ID="Literal15" runat="server" Text="<%$Resources:ThumbnailNote %>"></asp:Literal>

    Also is this whole process posible without recompiling the code?

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Jan 31, 2011 (permalink)

    Hi,

    Please make sure that you have registered TagPrefix for sfLib. This is a general ASP.NET error.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Iain avatar

    Posted on Feb 3, 2011 (permalink)

    Would of been helpful to mention this line of code in the snippet at the top of this tread

    <%@ Register TagPrefix="sfLib" Namespace="Telerik.Libraries.WebControls" Assembly="Telerik.Libraries" %>

    So I have the thumbnail in the blog postnew and postedit template and this field is updated correctly in the back end... but when displaying this in the contentViewItemList template the <img> src attribute is blank?

    What have I missed?

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Feb 3, 2011 (permalink)

    Hi,

    Does the meta key gets saved when you Edit, Create the item. You should see this in preview mode. If the item is not saved

    1. It is not defined in the web.config
    2. You have not added the ButtonSelector inside ContentMetaFields control and you are not using ITextControl to persist the metakey value.

    Another option is that you are not resolving the value returned by the selector on the public part of the website. If the value is dynamic link you have to use GetItemUrl method listed above.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Iain avatar

    Posted on Feb 3, 2011 (permalink)

    The data is saved and visible through the preview.

    I also added a summary field using the same technique and this appears correct, so I guess this is not resolving the URL, where should the code be placed? Can it be placed in a code block rather than within a .cs file?

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Feb 3, 2011 (permalink)

    Hi,

    You can use code block in the template, but it is better to use the custom control provided above.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Iain avatar

    Posted on Feb 3, 2011 (permalink)

    Is there a solution example in the code libraries as I dont seem to be getting anywhere


    Grrr....!

    Reply

  • Iain avatar

    Posted on Feb 23, 2011 (permalink)

    Hi Ivan,

    After retracing my steps I have made some small progress. I wasnt able to create a custom class but was able to get the thumbnail data from the metafields into the control template (Sitefinity\ControlTemplates\Blogs\ContentViewItemList.aspx) , the thumbnail data is held as "~images/Thumb1.jpg".

    I can display this fine as a literal in the template but am unable to use this to display an image?

    Any suggestions for an amateur?


    Cheers


    Iain

    Reply

  • Register for webinar
Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): Developing with Sitefinity > Adding Thumbnails to blog