如何隐藏一些 Kentico 博客评论字段?
当使用 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
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用哪个版本的 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).
我们研究了 Web 部件代码,发现 Kentico 5.5 不提供通过 Web 部件属性自定义它们的功能,甚至也不提供自定义 Web 部件,因为博客模块甚至不提供这种功能。所以我们这样做了:
~/CMSModules/Blogs/Controls/BlogCommentView.ascx
和~/CMSModules/Blogs/Controls/BlogCommentEdit.ascx
并重命名它们...View.ascx
引用新的...Edit.ascx
...Edit.ascx
的@Register Src="..."
属性更改为指向到新的...Edit.ascx
行上设置
style="display:none"
使用默认值。 (该网站已经需要身份验证,因此用户名已填写到“名称”字段中,并且在我们的示例中未使用“电子邮件”和“URL”字段,因此其中的内容并不重要,因为我们不需要每个博客设置的电子邮件字段。)...View.ascx
:刚刚更改的新布局代码
@Register
元素中的Src
属性: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:
~/CMSModules/Blogs/Controls/BlogCommentView.ascx
and~/CMSModules/Blogs/Controls/BlogCommentEdit.ascx
and renamed them...View.ascx
to reference the new...Edit.ascx
...Edit.ascx
's@Register Src="..."
attribute to point to the new...Edit.ascx
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.)...View.ascx
:The new Layout code that just changed the
Src
attribute in the@Register
element: