Domanda

When use Kentico for a Blog with Comments, it has the following fields:

  • Name
  • E-mail
  • Your URL
  • Comments

But I want to use the current authenticated user's name, and don't need the E-mail or Your URL options.

On one-off pages, we can use CSS to set the fields to display:none by their HTML IDs, but that won't work for Blogs because the IDs will change often since they are generated by ASP.NET based on the control tree.

Is there a way to hide these fields by configuring the BlogComments web part (we can't find any settings in there for them), or do we have to replace the BlogComments web part with custom code?

UPDATE: Looks like you can't do this without customizing code (see accepted answer below), at least in v5.5 R2 and older; maybe not in v6 either? Vote for the feature suggestion to add it at to a future version of Kentico in this Kentico UserVoice request.

È stato utile?

Soluzione 2

We looked into the web part code, and Kentico 5.5 does not offer the ability to customize them via web part properties, nor even with a custom web part since the blog module doesn't even offer it. So we did this:

  1. Copied ~/CMSModules/Blogs/Controls/BlogCommentView.ascx and ~/CMSModules/Blogs/Controls/BlogCommentEdit.ascx and renamed them
  2. Updated the codefile/inherits attributes in those new files to use custom class names and for the ...View.ascx to reference the new ...Edit.ascx
  3. Changed our new ...Edit.ascx's @Register Src="..." attribute to point to the new ...Edit.ascx
  4. Set style="display:none" on the <tr> rows that we just wanted to use the defaults. (This site required authentication already, so the user's name was already filled into the Name field, and the E-mail and URL fields aren't used in our case so it didn't matter what was in them since we didn't require the E-mail field per the Blog settings.)
  5. In the original web part we created on our customized Portal template, changed the Layout to a new, custom Layout that points to the new ...View.ascx:

The new Layout code that just changed the Src attribute in the @Register element:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="~/CMSWebParts/Blogs/BlogCommentView.ascx.cs" Inherits="CMSWebParts_Blogs_BlogCommentView" %>
<%@ Register Src="~/CustomBlogCommentView.ascx" TagName="BlogCommentView" TagPrefix="cms" %>

<cms:BlogCommentView ID="commentView" runat="server" />

Altri suggerimenti

Which version of Kentico CMS do you use? I just checked the 5.5R2 version and the user name and e-mail are filled in automatically in blog comments if the user is authenticated.

To hide the fields you do not need you will need to change the code of the control used in this web part - \CMSModules\Blogs\Controls\BlogCommentEdit.ascx.cs (please be aware of your changes when upgrading/hotfixing).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top