跳到内容
请注意::本文仅为方便您阅读而提供。本文由翻译软件自动翻译,可能未经校对。本文的英文版应被视为官方版本,您可在此找到最新信息。您可以在此处访问。

在设计管理器中创建和编辑模块

上次更新时间: 2025年10月24日

可与以下任何订阅一起使用,除非另有说明:

通过设计管理器,您可以创建自定义模块,为博客、页面或电子邮件添加高级功能。自定义模块提供多种功能,因此可以在页面、电子邮件或博客编辑器中完全自定义内容。

请注意:创建模块需要了解 HTML、CSS、HubL 和 HubSpot 设计管理器。HubSpot 建议与开发人员合作创建编码模块。

创建新模块

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 搜索器顶部,单击 "文件"下拉菜单并选择 "新建文件"。

In the design manager, within the finder, a box is placed around the File dropdown menu and the options are displayed. An arrow points to the 'New file' option.

  1. 在对话框中,单击 "今天要创建什么?"下拉菜单并选择 "模块"。
  2. 单击下一步。
  3. 在 "您希望在何处使用此模块"字段中,选择将使用模块的每种内容类型旁边的复选框(例如,博客文章电子邮件登陆页面)。
  4. 模块内容范围字段中,选择一个选项(如 本地模块全局模块)。如果创建的是全局模块,编辑该模块的内容将更新使用该模块的所有位置。
  5. 输入模块的文件名
  6. 要更改模块的文件位置,请单击 "文件位置"部分中的 "更改"。在弹出框中选择一个新位置,然后单击 "选择"。
  7. 完成后,单击 "创建"。
  8. 继续编辑模块

请注意:电子邮件中使用的模块只能在订阅了Marketing HubProfessionalEnterprise 的账户中创建。它们不能包含 CSS 或 JavaScript。

编辑模块

在设计管理器中创建模块后,您可以自定义其功能和外观。为模块加上清晰的标签,添加和配置字段,调整字段编辑器选项(如默认内容)。设置显示条件和中继器选项,并对相关字段进行分组,以便更好地组织。您还可以复制和粘贴字段片段、编写自定义模块语法、添加有用的说明性文字,以及编辑模块可使用的模板类型。

为模块添加标签

在设计管理器中,您可以为模块添加或更新标签,以帮助用户在内容编辑器中识别模块。如果标签为空,则默认显示模块名称。

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 查找器中,单击打开要编辑标签的模块
  3. 检查器中输入标签
In the design manager, the inspector is displayed for a module. At the top of the inspector, the label field is empty.

为模块添加字段

向模块添加字段可设置模块的内容或样式,并使其可在内容编辑器中编辑。进一步了解可用字段类型

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 查找器中,点击打开一个模块
  3. 在 "检查器"的 "字段"部分,单击 "添加字段"下拉菜单。然后选择一个字段添加到模块中。

In the design manager, the inspector is displayed for a module. In the Fields section, a box is placed around the Add field dropdown menu.

  1. 要编辑字段名称,请单击edit 编辑图标并输入新名称。要编辑 HubL 变量名,请在HubL 变量名字段中输入新名称

In the design manager, the inspector is displayed for a module field. At the top of the module field's details is a box placed around the edit icon to edit the name of the module field. An arrow points to the HubL variable name text input field with a value of 'event_date_and_time'.

自定义字段默认内容

在 "内容选项 "部分,您可以添加默认内容,当模块在模板和内容编辑器中使用时,默认内容就会出现。默认内容的选项因字段类型而异。

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 查找器中,单击打开模块
  3. 在 "检查器"的 "字段"部分,将鼠标悬停在 上并单击 "编辑"。
  4. 内容选项部分,添加或编辑默认内容选项。可用的默认内容选项取决于所选的字段类型。

例如,在模块中添加日期和时间字段类型后,可以选择默认日期和时间。还可以输入默认时间间隔。

In the design manager, the inspector displays a field's default content options. For the Date and time field type, you can select a default date and time. You can also select a time interval in minutes.

设置字段编辑器选项

在 "编辑器选项 "部分,您可以在内容编辑器中将字段设置为必填字段并阻止编辑。还可以自定义帮助文本。

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 查找器中,单击打开模块
  3. 在 "检查器"的 "字段"部分,将鼠标悬停在段上并单击 "编辑"。
  4. 在 "编辑器选项"部分,要使字段成为必填字段,请打开 "使此字段成为必填字段"开关。这将防止用户在内容编辑器中将字段留空。
  5. 要防止字段内容被编辑,请打开 "防止在内容编辑器中编辑"开关。字段内容仍可在设计管理器中的模板级别进行自定义。此选项不适用于全局模块
  6. 要添加有关如何使用字段的上下文或说明,请在工具提示帮助文本字段内联帮助文本字段 中输入文本
    • 工具提示帮助文本:当用户在内容编辑器中将鼠标悬停在infoCircleIcon info 图标上时,该文本将显示在工具提示中。
    • 内联帮助文本:当用户在内容编辑器中编辑模块时,该文本将显示在字段下方。

In the design manager, the inspector shows a field's editor options. These options include making the field required, preventing editing in the content editor, and adding help text.

设置字段显示条件

在 "显示条件"部分,您可以使用字段显示条件设置模块字段,使其仅在另一个字段满足特定条件时才显示。

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 查找器中,单击打开模块
  3. 在 "检查器"的 "字段"部分,将鼠标悬停在段上并单击 "编辑"。
  4. 显示条件部分,单击HubL 变量 下拉菜单并选择一个变量
  5. 单击第二个下拉菜单并选择一个 选项(例如,等于 不为空)。根据所选选项,可能需要更多条件字段。例如,如果选择 "等于",则需要额外的值字段。
  6. 默认情况下,一旦配置了条件,就会自动打开显示条件。要关闭显示条件,请切换显示 条件开关。

In the design manager, the inspector shows a field's display conditions. At the top of the section, a toggle is switched on for Display conditions. The HubL variable dropdown menu has the event_date_and_time variable selected. The condition dropdown menu has the Is not empty condition selected.

设置字段中继器选项

中继器选项部分,可以为字段和组配置中继器选项。打开中继器选项后,将使用for 循环创建和显示多个对象。

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 查找器中,单击打开一个模块
  3. 在 "检查器"的 "字段"部分,将鼠标悬停在段上并单击 "编辑"。
  4. 中继器选项 部分,在最小最大 (可选)字段中输入一个数字。这将设置字段在模块中出现的最小次数,直至最大值。
  5. 要设置字段的默认显示次数,请在 "默认对象计数"字段中输入一个数字
  6. 默认情况下,中继器选项一经配置就会自动开启。要关闭中继器选项,请切换中继器选项 开关。

例如,更改图像字段的中继器选项,可显示至少三个、最多五个图像字段。默认值为四个图像字段。在内容编辑器中,用户将默认看到四个图像字段,并可增加一个图像字段或删除一个现有图像字段。

In the design manager, the inspector shows a field's repeater options. At the top of the section, a toggle is switched on for Repeater options. A minimum value of three and a maximum value (optional) of five are configured. The default object count contains a value of four.

分组模块字段

创建字段后,可以对它们进行分组,以便按相关性对字段进行组织。字段组可用于建立自定义字段逻辑。您最多可以将四个字段分组。进一步了解模块字段组

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 查找器中,单击打开一个模块
  3. 检查器的 "字段"部分,单击 "操作"下拉菜单并选择 "分组"。
  4. 选择要分组的一个或多个字段,然后单击创建分组

In the design manager, the inspector shows a module's Fields section. A box is placed around the Actions dropdown menu and the options are displayed. An arrow points to the Group option.

为模块添加帮助文本

在 "编辑器选项"部分,您可以添加帮助文本,为用户提供编辑模块时的上下文。该文本将显示在模块字段的上方。

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 查找器中,单击打开一个模块
  3. 在 "检查器"的 "编辑器选项 "部分,在 "内联帮助文本"字段中输入文本

In the design manager, the inspector shows a module's Editor options section. The Inline help text field contains the following text: Example help text that gives user's context and instructions on what this module is used for and how to use it.

管理模块的内容类型和可用性

添加或删除用户可以使用模块的内容类型,如博客文章登陆页面。您还可以在模板和页面中打开或关闭模块的可用性。

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 查找器中,单击以打开模块
  3. 要编辑模块的内容类型,请单击右上方检查器中模块名称下方的内容类型
In the design manager, the inspector is displayed for a module. At the top of the inspector, a box is placed around the content types for the module (e.g., Landing pages, Site pages, Blog listing pages, Blog posts).
    • 在对话框中,选择或清除将使用或不使用模块的每种内容类型(如博客文章电子邮件登陆页面)旁边的复选框
    • 完成后,单击更新
  1. 要管理模块在模板或页面中的可用性,请切换右上角的 "使模板和页面可用 "开关要测试模块功能或关闭模块在模板和页面中的可用性,请切换 "使模块在模板和页面中可用 "开关。

请注意:关闭模板或页面可用性 开关不会从任何现有模板或页面中移除模块。

复制和粘贴字段片段

在模块中加入字段时,可将字段片段复制并粘贴到模块编辑器中的module.html (HTML + HubL)部分。

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 查找器中,点击打开模块
  3. 检查器中,将鼠标悬停在模块字段上,然后单击字段部分的操作下拉菜单。然后选择复制片段
  4. 模块编辑器中,将字段片段粘贴到module.html (HTML. + HubL)部分所需的位置。您可以使用键盘快捷键Cmd+V 或 Ctrl+V

编写模块语法

编辑模块时,可在module.html (HTML + HubL)module.cssmodule.js 模块编辑器部分编写模块语法。了解有关模块编辑器模块概述的更多信息。

预览和发布模块

完成模块编辑(包括添加字段和编写模块语法)后,就可以预览和发布模块了。

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 查找器中,单击打开模块
  3. 要预览模块,请单击右上角的 "预览"。你将被引导到一个新的浏览器标签页来预览模块。该预览会与模块编辑器同步,并在编辑发生时自动刷新。
  4. 要发布模块,请单击 "发布更改"

将模块添加到模板中

发布模块后,可以将其添加到设计管理器中的拖放模板或自定义编码模板中,从而在不同模板中使用。要在内容编辑器中添加模块,请了解有关在内容编辑器中添加和编辑模块的更多信息。

  1. 在 HubSpot 帐户中,导航到内容 > 设计管理器
  2. 查找器中,单击打开模板。
  3. 要在布局编辑器的拖放模板中添加模块,请单击检查器顶部的+ 添加选项卡。
    • 在 "搜索 "字段中输入模块名称。要将搜索范围缩小到自定义模块,请单击 "按类别或标签过滤"下拉菜单,然后选择 "自定义模块"。
    • 单击dragHandleIcon 拖放图标,将模块移动到布局编辑器中的位置。
  4. 将模块添加到自定义编码模板中:
    • 右键单击或按住 Ctrl+ 单击查找器中模块 ,然后选择复制片段。或者,单击打开模块,然后在检查器的 "模板使用"部分单击 "复制片段"。
    • 在自定义编码模板中,将模块片段粘贴到代码编辑器中。
  5. 完成后,单击右上角的 "发布更改"

示例

创建倒计时模块

  1. 在设计管理器中创建一个模块,将其命名为 "倒计时器"。
  2. 检查器的 "字段"部分,单击 "添加字段"下拉菜单。
    • 选择日期和时间字段。输入名称"事件日期和时间"。这将把HubL 变量名称字段更新为event_date_and_time
In the design manager, the inspector is displayed for a module field. At the top of the module field's details is a box placed around the edit icon to edit the name of the module field. An arrow points to the HubL variable name text input field with a value of 'event_date_and_time'.
    • 选择颜色字段。输入名称"计时器字体颜色"。这将更新HubL 变量名字段为timer_font_color

请注意:HubL 变量名必须与下面 module.html (HTML + HubL)代码部分包含的变量名一致。

  1. 模块编辑器中,将以下代码复制并粘贴到module.html (HTML + HubL) 部分:

<! -- 隐藏 span 以存储目标日期 -->
<span id="target-date" style="display: none;"></span> <!

<!-- 显示倒计时计时器 -->
<div style="float: left; width: 100%; color: ;"></span> <!
<div class="time_container" style="margin-left: 30%;">
<span id="days"></span><br> 天数
天数
</div
<div class="time_container">
<span id="hours"></span><br
小时
</div
<div class="time_container">
<span id="minutes"></span><br
分钟
</div
<div class="time_container">
<span id="seconds"></span><br

</div
</div

  1. 将以下代码复制并粘贴到module.css部分:

.time_container {
float: left;
width: 10%;
text-align: center;
}
.time_container span {
font-weight: bold;
font-size: 200%;
}

  1. 将以下代码复制并粘贴到module.js部分:

// 计算和显示倒计时的函数
function updateCountdown() {
// 从隐藏跨度中获取目标日期
const targetDate = new Date(document.getElementById('target-date').textContent);
// 获取当前日期
const currentDate = new Date();
// 计算剩余时间(以毫秒为单位)
const timeRemaining = targetDate - currentDate;
// 检查目标日期是否已过
if (timeRemaining <= 0) { document.getElementById('countdown').innerText = 'Countdown expired';
返回;
}
// 计算剩余天数、小时数、分钟数和秒数
const days = Math.floor(timeRemaining / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeRemaining % (1000 * 60 * 60 * 24))/ (1000 * 60 * 60));
const minutes = Math.floor((timeRemaining % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeRemaining % (1000 * 60)) / 1000);
// 显示倒计时
document.getElementById('days').innerText = `${days}`;
document.getElementById('hours').innerText = `${hours}`;
document.getElementById('minutes').innerText = `${minutes}`;
document.getElementById('seconds').innerText = `${seconds}`;
}
// 每秒更新一次倒计时
setInterval(updateCountdown, 1000);
// 初始调用立即更新倒计时
updateCountdown();

In the design manager, the code editor and the inspector are displayed for a module. Boxes are placed around the module.html, module.css, and the module.js sections in the. code editor.

  1. 完成后,预览并发布模块。
  2. 继续将模块添加到模板中
这篇文章有帮助吗?
此表单仅供记载反馈。了解如何获取 HubSpot 帮助