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

Forums / Bugs & Issues / How to Customize Blogs

How to Customize Blogs

2 posts, 0 answered
  1. Ankit
    Ankit avatar
    13 posts
    Registered:
    29 Jul 2011
    18 Aug 2011
    Link to this post
    Hello Everyone,
    I want to customize the fields of Blogs for Comments,I am having an sitefinity4.2  Application  including an  Login Control Page  to Login the registered User, I want only to Use 'Name(Optional)', and the 'Loggedin  UserId' Field during Posting the Comments and also to send an Email notification to the Admin about the Comment Posted. Please Provide a demo code to do that..

    Thanks,
    Ankit Rastogi
  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    18 Sep 2017
    22 Aug 2011
    Link to this post
    Hi Ankit,

    To achieve this you should map a template for comments implementing a logic that will take the username and fill the textbox. Here is the template for CommentsDetailsVeiw
    <%@ Control Language="C#" %>
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" TagPrefix="sf" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" %>
      
    <asp:Panel ID="authenticatedUserContainer" runat="server" CssClass="sfcommentsFormWrp">
        <asp:Panel ID="moderationContainer" runat="server" Visible="false">
            <p class="sfNeutral">
                <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:ContentResources, CommentMessageModeration %>" />
            </p>
        </asp:Panel>
        <h2 class="sfcommentsTitle"><asp:Literal ID="Literal2" runat="server" Text="<%$Resources:ContentResources, Comment%>" /></h2>
        <fieldset class="sfcommentsForm">
            <ol class="sfcommentsFieldsList">
                <li id="authorNameControlWrapper" runat="server" class="sfcommentsField">
                    <sf:TextField
                        ID="authorName"
                        runat="server"
                        DisplayMode ="Write"
                        Title="<%$Resources:ContentResources, YourName%>"> CommentsDetailsView
                            <ValidatorDefinition
                                Required="true"
                                RequiredViolationMessage="<%$Resources:ContentResources, NameCannotBeEmpty %>"
                                MessageCssClass="sfError" />
                    </sf:TextField>
                </li>
                <li id="emailControlWrapper" runat="server" class="sfcommentsField">
                    <sf:TextField
                        ID="email"
                        runat="server"
                        DisplayMode ="Write"
                        Title="<%$Resources:ContentResources, EmailOptional %>">
                            <ValidatorDefinition
                                RequiredViolationMessage="<%$Resources:ContentResources, EmailCannotBeEmpty %>"
                                ExpectedFormat="EmailAddress"
                                Required="false"
                                MessageCssClass="sfError" />
                    </sf:TextField>
                </li>         
                <li id="websiteControlWrapper" runat="server" class="sfcommentsField">
                    <sf:TextField
                        ID="website"
                        runat="server"
                        DisplayMode ="Write"
                        Title="<%$Resources:ContentResources, WebsiteOptional%>">
                            <ValidatorDefinition
                                RequiredViolationMessage= "<%$Resources:ContentResources, WebSiteCannotBeEmpty %>"
                                ExpectedFormat="InternetUrl"
                                Required="false"
                                MessageCssClass="sfError" />
                    </sf:TextField>
                </li>
                <li id="contentControlWrapper" runat="server" class="sfcommentEditor sfcommentsField">
                    <sf:HtmlField
                        ID="content"
                        runat="server"
                        DisplayMode="Write"
                        EditorToolsConfiguration="Minimal"
                        HtmlFieldEditModes="Design"
                        Title="<%$Resources:ContentResources, Comment%>"
                        EditorContentFilters="DefaultFilters"
                        EditorStripFormattingOptions="AllExceptNewLines"
                        Height="200"
                        IsToOverrideDialogs="false">
                            <ValidatorDefinition
                                RequiredViolationMessage="<%$Resources:ContentResources, CommentCannotBeEmpty %>"
                                Required="true"
                                MessageCssClass="sfError" />
                    </sf:HtmlField>
                </li>
                <li id="captchaWrapper" runat="server" class="sfcommentsField sfcommentCaptcha">
                    <telerik:RadCaptcha ID="captcha" runat="server" ErrorMessage="<%$Resources:ContentResources, PageNotValid %>" Display="Dynamic" Skin="Sitefinity" />
                </li>
            </ol>
            <div class="sfcommentsSubmitBtnWrp">
                <asp:Button ID="submitBtn" runat="server" Text="<%$Resources:ContentResources, Submit%>" CommandName="submitComment" CausesValidation="true" class="sfcommentsSubmitBtn" />
            </div>
        </fieldset>
    </asp:Panel>
    <asp:Panel ID="anonymousUserContainer" runat="server" Visible="false">
        <p>
            <asp:Literal ID="Literal3" runat="server" Text="<%$Resources:ContentResources, PostingCommentsIsNotAllowed %>" />
        </p>
    </asp:Panel>
    Set the template build action to embedded resource. To add it to your project go to Administration->Settings->Advanced->ContentView->Controls and choose where you need it for example NewsContentFrontend->Views->CommentsDetailsView and in the field ViewType enter the path to code file(namespace.class).
    The code file:
    The code file should be a .cs document inheriting from ViewBase. There you should provide a logic that will take the name of the currently logged user and pass it to the textfield or asp:Label. Here is a forum topic providing the API code for getting the current user.
    In the code file specify the template used like this:
    protected override string LayoutTemplateName
            {
                get
                {
                    return null;
                }
            }
       
            public override string LayoutTemplatePath
            {
                get
                {
                    return Test.layoutTemplate;
                }
                 
            }
    private const string layoutTemplate = "~/VppPrefix/SitefinityWebApp.MasterView.Comments.ascx";
        }
    Note when adding the virtual path and new View restart the application by making a dummy change in the web.config.

    For e-mail sending functionality you should subscribe to the event that is fired when commens are posted and use Emailsender
    EmailSender.Get().TrySend(new MailMessage(new MailAddress("mail address"), new MailAddress("mail address")));
    This will send e-mail to the target mail in the code using Sitefinity SMTP settings(Administration->Settings->Advanced->System->Smtp). Here is related documentation.

    Greetings,
    Stanislav Velikov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

2 posts, 0 answered