+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Extending Existing Modules

Extending Existing Modules

18 posts, 0 answered
  1. pbwebmaster
    pbwebmaster avatar
    17 posts
    Registered:
    15 Apr 2007
    04 Oct 2007
    Link to this post
    I need to extend the News module so that attachments can be included along with each news item (we're using it for press releases, and attaching a PDF version with each release is one of the client's requirements). 

    I haven't been able to find much documentation for extending the existing built-in modules--can you provide some general recommendations for doing so?  Of course, we won't be able to avoid merge issues every time Sitefinity is updated, but some tips on how to minimize those issues would be greatly appreciated as well.

    Thanks!

    Brett
  2. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    05 Oct 2007
    Link to this post
    This might not be as complete a solution as you were hoping. However,  you can simply use the document manager to include a link to the pdf at the beginning of the news item.

    Sincerely,

    Ben
  3. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    08 Oct 2007
    Link to this post
    Hi Brett,

    Actually there is a very simple way to achieve this.
    All Generic Content based modules (Generic Content, News, Blogs) have the ability to define custom meta fields. So the basic idea is to define a PDFAttachement meta field to News module, add control that will accept the URL of the attachement and then in SingleNews and/or NewsList control add hyperlink control that will display this URL (for your PDF attachement). That's the solution in short. I'll give you now some more detailed instructions.

    Defining a new meta field

    Open the web.config file. In the <cmsEngine> section find the <metaFields> section. You'll see there numerous meta fields that modules use by default. Add the following key :

    <add key="News.PDFAttachement" valueType="ShortText" visible="True" searchable="false" sortable="False" defaultValue=""></add>


    Basically, you are telling Sitefinity that with each news item a PDFAttachement field, which is of ShortText type will be stored. So far so good. Now you need to provide some user interface in the admin area for your users to enter the URL of .PDF file for the news item.

    Modifying admin templates

    Next thing you need to do is modify the templates that Sitefinity uses for inserting new news items and editing existing news items. To do so, you need to open in Visual Studio following files :
    • ~/Sitefinity/Admin/ControlTemplates/News/ControlPanelInsert.ascx and
    • ~/Sitefinity/Admin/ControlTemplates/News/ControlPanelEdit.ascx

    Observe how we have created the markup for e.g. Author meta field. You have two options here, you can just add TextBox control and set it's id to PDFAttachement (that's how Sitefinity knows that value of this textbox should be used for saving/displaying PDFAttachement meta field). The drawback of this solution is obviously that the user needs to know exact URL of the attachment (I assume that attachments would be uploaded through the File Manager). Another option you have is to create a custom control that would have maybe a "Select document to attach button". When this button is clicked, you can open RadWindow or something like that and provide a File System treeview, so your users can select the document they wish to attach. If you decide to use a custom control, make sure it implements ITextControl interface; it is the Text property that will be used as value of your meta field.

    So, after you've done this, you have set up everything on the administration side. Users have the option to attach a document (by setting the .PDF document URL) to a news item, they can edit it later or remove it. The last step is to display this link on the news public control.

    Displaying meta field values on public controls

    Once again we are going to modify the templates, only this time we are going to do that for the public controls. Let's assume you only want the PDF attachment link to appear only when user opens a news item. In that case, you only need to modify the template for the SingleNews control. Open the following file in Visual Studio :

    • ~/Sitefinity/ControlTemplates/SingleNews.ascx

    What you want to do in this template is very similar to what you have already done in the admin templates. You will add a Hyperlink control that has the id same as the meta key (PDFAttachement) so that Sitefinity knows that this is the control to which the value of that meta field will be bound. However, Sitefinity will only bind the Text property, so you are still left with setting the NavigateUrl. Here you can use a little trick, so your Hyperlink control looks like this :

    <asp:HyperLink ID="PDFAttachement" runat="server" NavigateUrl='<% = this.Text %>'></asp:HyperLink>

    Basically, you tell the control that the NavigateUrl property is same as the Text property of that control, and the text property will be set by Sitefinity.

    And that's it.

    Obviously you have countless options here... You could have added two meta fields (attachement file title ad attachement file url), or you can make the meta field to store the collection of files (delimited by semi-colon ";")... it is up to you, but this is the basic principle I would use if it is up to me to create this kind of functionality.

    I hope this helps. Let me know if you need any clarifications.

    All the best,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. pbwebmaster
    pbwebmaster avatar
    17 posts
    Registered:
    15 Apr 2007
    08 Oct 2007
    Link to this post
    Ivan, that's fantastic...thanks for such a thorough and helpful response!

    Ben, thanks for your response too...you're right, I was looking for something a little more than that, but it certainly would have worked for a temporary solution.  :o)
  5. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    16 Jul 2008
    Link to this post
    any chance to be able to define what property will be defined by the meta? that way I can set different link for text and link.
  6. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    16 Jul 2008
    Link to this post
    wait, the sample above doesn't work, it's actually trying to embed the actual text < %= this.Text %> into the navigate field!
  7. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    17 Jul 2008
    Link to this post
    Hello SelArom,

    One of the reasons why the sample may not work is because user controls will by default use VB.NET if not other specified, and the given sample is in C#. You can try to use Me.Text instead of this.Text.

    However, this approach may prove to be limited in some scenarios. I've created a sample control (it's not production quality and not official part of Sitefinity - but it does work and it's open source) which lets you map meta fields to any property. More about this control, as well as the download link, you can find at this link:

    http://blogs.sitefinity.com/Ivan/Post/08-07-03/metamaster_2008_finally_released_.aspx

    I hope you'll find this information useful. Let us know if there is anything else we can do for you.

    All the best,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    17 Jul 2008
    Link to this post
    that is an AWESOME TOOL! thank you for providing it, it fills a HUGE gap in sf, man I love sf it gets better every day

    thanks!
  9. Hydo L
    Hydo L avatar
    98 posts
    Registered:
    31 Mar 2010
    21 Aug 2010
    Link to this post
    Hi,
    I am using sitefinity version 3.7 and I can not find the  files
    • ~/Sitefinity/Admin/ControlTemplates/News/ControlPanelInsert.ascx and
    • ~/Sitefinity/Admin/ControlTemplates/News/ControlPanelEdit.ascx
    can you please help me in this

    Thanks,
    Hydo
  10. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    22 Aug 2010
    Link to this post
    Hi Hydo,

    You need to download the external templates from your account and use the following templates:

    ~/Sitefinity/Admin/ControlTemplates/NewsItemNew.ascx 
    ~/Sitefinity/Admin/ControlTemplates/NewsItemEdit.ascx

    Best


  11. xor
    xor avatar
    42 posts
    Registered:
    04 Jan 2010
    27 Aug 2010
    Link to this post
    Hi,

    I need to extend the news module to add another field (as a workaround for the title length limitation)
    I defined the meta field as follows

    <add key="News.Header" valueType="LongText" visible="True" searchable="false" sortable="False" defaultValue=""></add>

    and downloaded and modified the external templates that Sitefinity uses for inserting new news items and editing existing news items:
    • ~/Sitefinity/Admin/ControlTemplates/News/ControlPanelInsert.ascx and
    • ~/Sitefinity/Admin/ControlTemplates/News/ControlPanelEdit.ascx

     

    <h3>
        <asp:Literal ID="Literal3" runat="server" Text="<%$Resources:Header %>"></asp:Literal>
        * <em id="headerEditorLabel" runat="server"></em>
    </h3>
    <fieldset class="set">
        <div class="setIn">
            <asp:TextBox ID="Header" Text="<%$Resources:HeaderInput %>" runat="server" MaxLength="250"
                ValidationGroup="EditNews"></asp:TextBox>
            <asp:RequiredFieldValidator ID="valHeader" runat="server" ControlToValidate="Header"
                Display="Dynamic" EnableViewState="False" CssClass="validMessage" SetFocusOnError="True"
                ValidationGroup="EditNews">
                <strong>
                    <asp:Literal ID="Literal4" runat="server" Text="<%$Resources:HeaderEmpty %>"></asp:Literal></strong></asp:RequiredFieldValidator>
        </div>
    </fieldset>

    and added the follwoing to Telerik.Sitefinity.Configuration.ControlsConfig.xml:
    <viewSettings hostType="Telerik.News.WebControls.Admin.NewsItemEdit" layoutTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/NewsItemEdit.ascx" />
    <viewSettings hostType="Telerik.News.WebControls.Admin.NewsItemNew" layoutTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/NewsItemNew.ascx" />

    After testing the solution, i found that the new field value is not getting saved. Is there anything missing in this configuration?

    Thanks in advance
    Fadi
  12. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    27 Aug 2010
    Link to this post
    Hello Fadi Raheel,

    The textbox for settign the Header meta field should be added in the ItemTemplate of the ContentMetaFields control otherwise it would not be persisted automatically:
    <sf:ContentMetaFields ID="MetaFields" runat="server">
        <ItemTemplate>
            ...
        </ItemTemplate>
    </sf:ContentMetaFields>

    Then when you add the view settings in the controls configuration file your website should be restarted for the changes in templates to take effect.

    Regards,
    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
  13. Daniel Gibson
    Daniel Gibson avatar
    4 posts
    Registered:
    20 Nov 2009
    01 Dec 2010
    Link to this post
    I also need to be able to include custom meta field links, and I've tried using <% = this.Text %> and it doesn't work. I looked at Ivan's MetaMaster control but it says it only works with detail pages and I need it to work on list pages.

    Can someone give me a straightforward answer regarding getting the hyperlink control to display custom metafield links? I am not an ASP.NET programmer so please include any necessary code examples.

    Also, I am working with a customized version of Telerik's sample products module.

    Thanks!
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    01 Dec 2010
    Link to this post
    Hi Daniel,

    You cannot use <% = this.Text %> because the metafields are not properties of the data item. If you just want to set the text you can add Literal inside a HyperLink control

    <asp:HyperLink ID="Link1" runat="server">
         <asp:Literal ID="NameOfYourMetakey" runat="server" />
    </asp:HyperLink>

    Another option is subscribing for ItemDataBound event of the repeater that is used to bind the items (ListPageMaster.ascx template), accessing the hyperlink in the event, getting the data item as IContent and setting some of the Hyperlink properties.

    sample

    public void Page_Load(object sender, EventArgs e)
       {
           repeater.ItemDataBound += new RepeaterItemEventHandler(repeater_ItemDataBound);
            
       }
       void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
       {
           if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
           {
               var hl = e.Item.FindControl("myLink") as HyperLink;
               var cnt = e.Item.DataItem as Telerik.Cms.Engine.IContent;
               var data = (string)cnt.GetMetaData("MyStringValue");
               hl.NavigateUrl = data;
               hl.Text = "some other value";
     
               
           }
       }


    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
  15. Venkat
    Venkat avatar
    105 posts
    Registered:
    20 Nov 2008
    21 Dec 2010
    Link to this post
    Hi Ivan ,Greetings to you,

    I think the below link was broken.
    In our app ,I want to add a meta filed for image path.I would like to give user the ability to select it using sitefinity file selector.
    Can you please provide me an example code.
    Thanks
    Venkat
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    21 Dec 2010
    Link to this post
    Hi Venkat,

    1. Here is the updated link to the MetaMaster
    2. You can use ButtonSelector. Please check the posts in this thread.

    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
  17. Venkat
    Venkat avatar
    105 posts
    Registered:
    20 Nov 2008
    21 Dec 2010
    Link to this post
    Ivan,
    Thank you for your reply.It helped me a lot and Now My meta field for Image path working fine.

    Can you help me on this:

    In our custom module , we want show our own user control which provides interface to select blog posts in place of
    ImageEditor dialogue.User can select more than one post.selected post ids are stored in a string separated with semi colon (;).
    I want to populate  this value in our custom module property , when the dialog window closes.

    Here is our code sample:
    <sfLib:ButtonSelector WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ArticleSelector.aspx"
                                 ItemTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/Dialogs/ButtonSelector.ascx" AssociatedControls="tbMainArticles"
                                  runat="server" cssclass="pickerWrapper" ButtonText="Select" />

    Can I use Button selector template for this?.

    Please help me on this.
    Thanks
    Venkat
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    21 Dec 2010
    Link to this post
    Hello Venkat,

    You should create a custom selector similar to this one here.

    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
Register for webinar
18 posts, 0 answered