Suite | Growth, Professional, Enterprise, or Enterprise Plus |
Support with | Guide all plans |
您可以使用 JavaScript 和 jQuery 轻松自定义帮助中心的外观和风格。本指南旨在帮助您根据需要打造帮助中心。
默认不提供 jQuery。要在主题中使用 jQuery 语句代替普通的 JavaScript,请务必导入 jQuery 库。有关更多信息,请参阅导入或升级 jQuery。
您还可以使用帮助中心模板化语言或 CSS 自定义帮助中心:
配方列表
我们会逐渐添加更多配方,但不可能面面俱到。您可以随心所欲使用 JavaScript 完成许多操作。请将您的配方发表在评论部分,以便我们将其添加到此指南中。
更改“我的活动”链接文本
将“我的活动”类添加到 header.hbs 模板:
{{link "my_activities" role="menuitem" class='my-activities'}}
将以下 jQuery 语句添加到 JavaScript 模板中的 $(document).ready(function()
函数:
$(' .my-activities').html(' See my requests');
隐藏“我的活动”的工单侧栏中的自定义字段
您可以使用 JavaScript 隐藏“我的活动”页面工单侧栏中的自定义字段。您可以根据标签选择自定义字段。例如,如果自定义字段的标签是“会员奖励”,而其标签中包含“会员”或“奖励”或“会员奖励”,则可以隐藏该字段。
在 script.js 文件中添加以下 jQuery 函数:
$(document).ready(function() {
if (window.location.href.indexOf('/requests') > -1) {
setTimeout(function() {
$('dt:contains("Member rewards")').hide().next('dd').hide();
// add more selectors as necessary
}, 1000); // adjust the timeout duration as needed
}});
重命名请求表格上的“标题”和“描述”标签
将以下 jQuery 语句添加到 JavaScript 模板中的 $(document).ready(function()
函数:
$('label[for=request_subject]').html("Custom Subject");
$('label[for=request_description]').html("Custom Description");
预填充自定义工单表格的字段
假设您在帮助中心使用自定义工单表格来允许用户注册产品。当用户在帮助中心打开表格时,您可以检测表格并预填充其中字段。
您将需要工单表格 ID(参见帮助中心中表格的 URL)。请参阅此示例。
以下 jQuery 示例将在标题字段中预填充“产品注册”,在描述字段中预填充“这是新产品注册”。将语句添加到 JavaScript 模板中的 $(document).ready(function()
函数:
var ticketForm = location.search.split('ticket_form_id=')[1];
if(ticketForm == 18570) {
$('section.main-column h1').html('Product Registration');
$('#request_subject').val('Product Registration');
$('#request_description').val('There is a new product registration.');
$('#request_subject').parent('.request_subject').hide(); // Hide subject
$('#request_description').parent('.request_description').hide();
$("<p>Please upload your product receipt here.<p>").insertAfter('label:contains("Attachments")'); // Adds text below "Attachments"
}
更改请求表格中自定义字段的顺序
您需要自定义字段的 ID(参见 Zendesk Support 界面)。请参阅此示例。
var firstName = $('input#request_custom_fields_22231170').parent();
var lastName = $('input#request_custom_fields_22231180').parent();
firstName.insertBefore($('input#request_subject').parent());
lastName.insertBefore($('input#request_subject').parent());
为请求表格添加标题
将以下 jQuery 语句添加到 JavaScript 模板中的 $(document).ready(function()
函数:
$('.form-field.request_anonymous_requester_email').prepend('<h2>Your personal information</h2>')
$('.form-field.request_subject').prepend('<h2>Your issue</h2>');
$('.form-field.request_custom_fields_21875914').prepend('<h2>Your device information</h2>');
$('.form-field.request_custom_fields_22033620').prepend('<h2>Your purchase information</h2>');
$('.form-field > label:contains("Attachments")').prepend('<h2>Support attachments</h2>');
隐藏语言下拉菜单中的语言
如果某种语言内容尚未准备好发布,则在语言选择器中隐藏该语言可能会有用。将以下 jQuery 语句添加到 JavaScript 模板中的 $(document).ready(function()
函数:
$("ul.dropdown-panel li a:contains('Français')").hide();
将语言选择器中的文本字符串替换为旗帜图标
例如,如果帮助中心提供美国英语和德语内容,则可以显示国旗,而不是语言选择器中的“美国英语”和“德语”。将以下 jQuery 语句添加到 JavaScript 模板中的 $(document).ready(function()
函数:
$(function(){
$('a.dropdown-toggle:contains("English (US)")').html('<img src="http://icons.iconarchive.com/icons/gosquared/flag/48/United-States-flat-icon.png" width="48" height="48">');
$('a.dropdown-toggle:contains("Deutsch")').html('<img src="http://icons.iconarchive.com/icons/gosquared/flag/48/Germany-flat-icon.png" width="48" height="48">');
$('a:contains("English (US)")').html('<img src="http://icons.iconarchive.com/icons/gosquared/flag/48/United-States-flat-icon.png" width="48" height="48">');
$('a:contains("Deutsch")').html('<img src="http://icons.iconarchive.com/icons/gosquared/flag/48/Germany-flat-icon.png" width="48" height="48">');
});
根据所选语言隐藏社区
将以下 jQuery 语句添加到 JavaScript 模板中的 $(document).ready(function()
函数:
if (document.location.pathname.match( (/hc\/de/) || (/hc\/es/) )) {
$('.community').hide();
}
阻止文章被搜索引擎编入索引
noindex
元标签会告诉搜索引擎不要在其索引中包含特定页面。要将 noindex
元标签动态添加到特定文章,请在 script.js 文件中添加以下函数:
(function () {
// Get the current page URL
const url = window.location.href;
// Check if the URL is an article page
if (url.indexOf("/articles/") == -1) {
return;
}
//List the ids of articles to be excluded from indexing
const articles = [5555300573850, 5500012959342]; //Example article ids
for (let i = 0; i < articles.length; i++) {
if (url.indexOf(articles[i]) !== -1) {
//Create a new meta tag element
var meta_tag = document.createElement("meta");
meta_tag.setAttribute("name", "robots");
meta_tag.setAttribute("content", "noindex");
//Append the meta tag to the head of the document
document.head.appendChild(meta_tag);
}
}
})();
41 条评论
Ashok Kumar Reddy Putta
I'm looking for help on ticket forms in the Help Center V4.1 Version. We currently have a URL(spreadsheets) in the description of a custom field. This is added for our customer to reference the information on this page while filling out the form.
The issue we have discovered is that when the customer clicks on the link it opens the URL in the same window as the Help Center.
Does anyone one know how to capture this via Javascript and force the link to open into a new tab within the users browser?
0
Abhinav Pandey
After upgrading to v4, accessing custom fields on the new request page using JavaScript or jQuery can be challenging since the previous field IDs (like
custom_field_122222
) are no longer available. Has anyone else encountered this issue or found a solution?0
Ruben Cortez
Hi everyone,
I'm struggling with the V4.0.2 template on a new brand we set up, to custom the request form.
My script.js file doesn't have the function $(document).ready(function()
I've tried several approaches and my changes aren't reflected, even adding the function near the bottom of the script .
What am I do wrong or missing?
Great community by the way. We customized a v2 template a while ago using solutions the community shared which works great.
Thanks
….
// If there are any error notifications below an input field, focus that field
const notificationElm = document.querySelector(".notification-error");
if (
notificationElm &&
notificationElm.previousElementSibling &&
typeof notificationElm.previousElementSibling.focus === "function"
) {
notificationElm.previousElementSibling.focus();
}
$(document).ready(function(){
$('label[for=request_subject]').html("Custom Subject");
$('label[for=request_description]').html("Custom Description");
}
});
})();
0
Dainne Kiara Lucena-Laxamana
Hi 1900354501104 !
You could following the guide posted here
0
Austin Kettler
Is it possible to display all the articles under a section rather than having the “see all x articles” link?
0
Mike DR
Glad to know you got the help you needed! Do feel free to reach out if you need more help!
0
VOC_운영
Hello! This is informative. I have one question, is it possible to make the name entered by the user as the requester name?
0
Kyle Kowalsky
1263082233249 that isn't quite what I was looking for, but that'll definitely come in handy. I was able to answer my own question here. Thanks!
0
Madison Hoffman
Hey Kyle! Did you see this tip from the community? https://support.zendesk.com/hc/en-us/community/posts/4409515169946-Requiring-a-ticket-attachment-if-a-particular-dropdown-option-is-selected
0
Kyle Kowalsky
We have a custom field that's a dropdown containing "Yes" and "No". I'd like to hide the attachments section if that dropdown is set to "No", but I can't seem to figure out the right if statement. Does anyone know if this is possible?
0
登录再写评论。