您可能需要更新文章的作者。要直接更改作者,您可以在用户界面中更改文章的作者。
但更改作者可能会遇到更复杂的场景。也许您想将某种语言的文章设置为显示特定作者,抑或希望在内部保留作者姓名,但在公开场合有统一或通用的作者姓名。这样的场景不胜枚举。本文章详细介绍了如何开始使用我们的帮助中心模板化语言。
本文章涵盖以下场景:
将所有作者更改为单个专员
主题中的默认文章页面如下所示:
文章模板上的默认代码如下所示:
<div class="article-avatar">
<img src="{{article.author.avatar_url}}" alt="Avatar"/>
</div>
<div class="article-meta">
<strong class="article-author" title="{{article.author.name}}">
{{#if article.author.url}}
<a href="{{article.author.url}}" target="_zendesk_lotus">{{article.author.name}}</a>
{{else}}
{{article.author.name}}
{{/if}}
</strong>
可在默认文章模板页面上找到该默认代码:
只需更改几个项目即可设置通用作者,包括头像和姓名。本例中,为免混淆,将删除作者 URL,仅显示图片和姓名。按照此处所述将新头像上传到资产,然后使用 资产助手调用该图像。
以下是本例中使用的代码:
<div class="article-avatar">
{{! User image changed here}}
<img src="{{asset 'user_image.jpg'}}" alt="Avatar"/>
</div>
<div class="article-meta">
{{! 'title' text and name changed here}}
<strong class="article-author" title="Help Desk Support">
Help Desk Support
</strong>
结果如下:
现在,我们已成功应用作者姓名,并显示一张新图像,而不是实际作者的头像。下面我们将在此基础上设置一个条件,仅显示特定语言/区域设置文章翻译的更改。
将某种语言的所有翻译更改为特定作者
根据您的支持情况,最好显示负责处理特定语言工单的专员,而不是为帮助中心创建内容的用户。我们可以使用一些逻辑通过 help_center 对象检查当前区域设置,并从中确定结果。
help_center.url
属性的条件语句不适用于“预览”,而仅适用于已发布主题。这是因为我们对 URL 进行了一些特殊调整,以便您在预览和编辑主题时单击切换页面。默认代码同上。通过一些附加条件,我们可以让您的体验与上一解决方案类似:
<div class="article-avatar">
{{! Checking the current locale value to replace the avatar}}
<img src="{{#is help_center.url '/hc/en-us'}}
{{asset 'user_image.jpg'}}
{{else}}
{{article.author.avatar_url}}
{{/is}}" alt="Avatar"/>
</div>
<div class="article-meta">
{{! Checking the current locale to set the author name}}
{{#is help_center.url '/hc/en-us'}}
<strong class="article-author" title="Language Support Team">
Language Support Team
{{! Fallback if current locale doesn't match above}}
{{else}}
<strong class="article-author" title="{{article.author.name}}">
{{#if article.author.url}}
<a href="{{article.author.url}}" target="_zendesk_lotus">
{{article.author.name}}
</a>
{{else}}
{{article.author.name}}
{{/if}}
{{/is}}
</strong>
您可能需要访问所需区域设置的帮助中心,才能获得文本字符串以替换上述
/hc/en-us
。如果您想设置多个条件,可以将
#is
条件语句相互嵌套,或为每个区域设置独立语句。如果您对这些类型的条件语句(is、if、each)感兴趣,请在此阅读更多。
按作者 ID 有选择地更改文章作者
您可能会遇到以下情况:一个主要参与者已离职或升职,但您希望在文章中看到 Support 中某人的头像。通过条件语句,我们可以检查作者身份,然后将其信息替换为剩余专员之一。
<div class="article-avatar">
{{! Checking the identity of the author to replace the avatar}}
<img src="{{#is article.author.id 319145489}}
{{asset 'user_image.jpg'}}
{{else}}
{{article.author.avatar_url}}
{{/is}}" alt="Avatar"/>
</div>
<div class="article-meta">
{{! Checking the identity of the author to replace the name with 'John Smith'}}
{{#is article.author.id 319145489}}
<strong class="article-author" title="Jill Smith">
Jill Smith
</strong>
{{! Fallback if author is not user 319145489}}
{{else}}
<strong class="article-author" title="{{article.author.name}}">
{{#if article.author.url}}
<a href="{{article.author.url}}" target="_zendesk_lotus">
{{article.author.name}}
</a>
{{else}}
{{article.author.name}}
{{/if}}
{{/is}}
</strong>
您还希望将上述
319145489
替换为要替换作者的用户 ID,而使用此解决方案,所有其他文章仍将显示其当前作者,只有用户
319145489
的文章将受到影响。
按文章 ID 有选择地更改文章作者
与上一解决方案类似,您也可以通过特定文章的 ID 更改作者。也许您想让特定主题的文章显示为由其他专员撰写。具体方法如下:
<div class="article-avatar">
{{! Checking the article id to replace the avatar}}
<img src="{{#is article.id 208598226}}
{{asset 'user_image.jpg'}}
{{else}}
{{article.author.avatar_url}}
{{/is}}" alt="Avatar"/>
</div>
<div class="article-meta">
{{! Checking the article id to replace the name}}
{{#is article.id 208598226}}
<strong class="article-author" title="John Smith">
John Smith
</strong>
{{! Fallback if article id is not 208598226}}
{{else}}
<strong class="article-author" title="{{article.author.name}}">
{{#if article.author.url}}
<a href="{{article.author.url}}" target="_zendesk_lotus">
{{article.author.name}}
</a>
{{else}}
{{article.author.name}}
{{/if}}
{{/is}}
</strong>
建议有限使用此解决方案。
is
助手无法检查一篇文章是否等于多个值(例如 or 语句),因此您必须相互嵌套多个条件语句才能检查多个文章 ID。
结合多个标准指定新作者
假设您想将一个专员显示为所有特定语言内容的作者,但只想替换一个作者。您可以设置多个条件语句来检查作者 ID 和区域设置等属性,然后根据这些条件进行操作(如下所示):
<div class="article-avatar">
<img src="{{#is help_center.url '/hc/ar'}}
{{#is article.author.id 319145489}}
{{! Avatar value if author is 319145489 and language is Arabic}}
{{asset 'user_image.jpg'}}
{{else}}
{{! Avatar value if author is not 319145489 and language is Arabic}}
{{article.author.avatar_url}}
{{/is}}
{{else}}
{{! Avatar value if language is not Arabic}}
{{article.author.avatar_url}}
{{/is}}" alt="Avatar"/>
</div>
<div class="article-meta">
{{#is help_center.url '/hc/ar'}}
{{#is article.author.id 319145489}}
{{! Author name if author id is 319145489 and language is Arabic}}
<strong class="article-author" title="John Smith">
John Smith
{{else}}
{{! Start Author Name if Arabic and not author 319145489}}
<strong class="article-author" title="{{article.author.name}}">
{{#if article.author.url}}
<a href="{{article.author.url}}" target="_zendesk_lotus">
{{article.author.name}}
</a>
{{else}}
{{article.author.name}}
{{/if}}
{{/is}}
{{else}}
{{! Start author name if not Arabic}}
<strong class="article-author" title="{{article.author.name}}">
{{#if article.author.url}}
<a href="{{article.author.url}}" target="_zendesk_lotus">
{{article.author.name}}
</a>
{{else}}
{{article.author.name}}
{{/if}}
{{/is}}
</strong>
鉴于条件语句的工作方式,以前这里必须重复一些代码才能满足所有情况,但现在我们已成功替换显示在仅限阿拉伯语文章上的特定作者。
0 条评论