如何隐藏一些 Kentico 博客评论字段?

发布于 2024-12-13 13:47:23 字数 609 浏览 0 评论 0原文

当使用 Kentico 作为带有评论的博客时,它具有以下字段:

  • 名称
  • 电子邮件
  • 您的 URL
  • 评论

但我想要使用当前经过身份验证的用户名,并且不需要“电子邮件”或“您的 URL”选项。

在一次性页面上,我们可以使用 CSS 通过 HTML ID 将字段设置为 display:none,但这不适用于博客,因为 ID 会经常更改,因为它们是由 ASP 生成的.NET 基于控件树。

有没有办法通过配置 BlogComments Web 部件来隐藏这些字段(我们在其中找不到它们的任何设置),或者我们是否必须用自定义代码替换 BlogComments Web 部件?

更新:看起来如果不自定义代码就无法做到这一点(请参阅下面接受的答案),至少在 v5.5 R2 及更早版本中;也许 v6 中也没有?在此Kentico UserVoice 请求中投票支持将其添加到 Kentico 未来版本的功能建议。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲念泪 2024-12-20 13:47:23

您使用哪个版本的 Kentico CMS?我刚刚检查了5.5R2版本,如果用户通过身份验证,则博客评论中会自动填写用户名和电子邮件。

要隐藏不需要的字段,您需要更改此 Web 部件中使用的控件的代码 - \CMSModules\Blogs\Controls\BlogCommentEdit.ascx.cs(请在升级/修补时注意您的更改)。

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).

吃素的狼 2024-12-20 13:47:23

我们研究了 Web 部件代码,发现 Kentico 5.5 不提供通过 Web 部件属性自定义它们的功能,甚至也不提供自定义 Web 部件,因为博客模块甚至不提供这种功能。所以我们这样做了:

  1. 复制 ~/CMSModules/Blogs/Controls/BlogCommentView.ascx~/CMSModules/Blogs/Controls/BlogCommentEdit.ascx 并重命名它们
  2. 更新了代码文件/继承这些新文件中的属性以使用自定义类名,并让 ...View.ascx 引用新的...Edit.ascx
  3. 将新的 ...Edit.ascx@Register Src="..." 属性更改为指向到新的 ...Edit.ascx
  4. 在我们想要的 行上设置 style="display:none"使用默认值。 (该网站已经需要身份验证,因此用户名已填写到“名称”字段中,并且在我们的示例中未使用“电子邮件”和“URL”字段,因此其中的内容并不重要,因为我们不需要每个博客设置的电子邮件字段。)
  5. 在我们在自定义门户模板上创建的原始 Web 部件中,将布局更改为新的自定义布局,该布局指向新的 ...View.ascx

刚刚更改的新布局代码@Register 元素中的 Src 属性:

<%@ 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" />

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" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文