基础替换

Basic Replacements

最基本的模板如下所示:

The most basic template looks something like this:

{{Front}}

当你将文本放在花括号内时,Anki 会根据该名称查找字段,并将文本替换为字段的实际内容。

When you place text within curly brackets, Anki looks for a field by that name, and replaces the text with the actual content of the field.

字段名称区分大小写。如果你有一个名为 Front 的字段,则写入{{front}}将无法正常工作。

Field names are case sensitive. If you have a field named Front, writing will not work properly.

模板不限制字段列表。你还可以在模板中包含任意文本。例如,如果你正在研究首都城市,并且你创建了一个带有“国家”字段的笔记模板,你可以创建一个像这样的正面模板:

Your templates are not limited to a list of fields. You can also include arbitrary text on your templates. For example, if you’re studying capital cities, and you’ve created a note type with a “Country” field, you might create a front template like this:

What's the capital city of {{Country}}?

默认的背面模板是这样的:

The default back template will look something like this:

{{FrontSide}}

<hr id=answer>

{{Back}}

这意味着“给我看正面的文本,然后是分隔线,然后是背面的字段”。

This means “show me the text that’s on the front side, then a divider line, and then the Back field”.

“id = answer”部分告诉 Anki 问题和答案之间的分隔符在哪里。这允许 Anki 在长卡上按“显示答案”时自动滚动到答案开始的位置(在小屏幕的移动设备上特别有用)。如果你不想在答案的开头有一条水平线,你可以使用另一个 HTML 元素,比 p 或 div。

The 'id=answer' part tells Anki where the divider is between the question and the answer. This allows Anki to automatically scroll to the spot where the answer starts when you press 'show answer' on a long card (especially useful on mobile devices with small screens). If you don’t want a horizontal line at the beginning of the answer, you can use another HTML element such as a paragraph or div instead.

新的一行

Newlines

卡片模板就像网页,这意味着需要一个特殊的命令来创建新行。例如,如果你在模板中编写了以下内容:

Card templates are like web pages, which means a special command is required to create a new line. For example, if you wrote the following in the template:

one
two

在预览中,你实际上可以看到:

Card templates are like web pages, which means a special command is required to create a new line. For example, if you wrote the following in the template:

one two

要添加新行,你需要在行尾添加<br>代码,如下所示:

To add a new line, you need to add a <br> code to the end of a line, like so:

one<br>
two

The br code stands for "(line) br(eak)".

对于字段来说也是一样的:

The same applies for fields. If you want to display two fields, one on each line, you would use

{{Field 1}}<br>
{{Field 2}}

文本发音

Text to Speech for individual fields

这个功能需要 Anki 2.1.20 以上版本,AnkiMobile 2.0.56 以上版本。AnkiDroid 暂不支持。

This feature requires Anki 2.1.20, or AnkiMobile 2.0.56. AnkiDroid does not currently support this method.

英语发音读取正面字段,你可以这样设置你的模板:

To have Anki read the Front field in a US English voice, you can place the following in your card template:

{{tts en_US:Front}}

Windows,Mac,iOS 上,Anki 会使用系统内置的发音。Linux 上没有内置发音,但你可以使用插件在新窗口打开

On Windows, macOS, and iOS, Anki will use the OS’s built in voices. On Linux, no voices are built in, but voices can be provided by add-ons, such as this one.

查看系统支持的语言,你在模板中写入如下:

To see a list of all available languages/voices, place the following on your card template:

{{tts-voices:}}

如果有多个语音支持你选择的语言,你可以在列表中指定所需的语音,Anki 将选择第一个可用的语音。例如:

If there are multiple voices that support your chosen language, you can specify desired voices in a list, and Anki will choose the first available voice. For example:

{{tts ja_JP voices=Apple_Otoya,Microsoft_Haruka:Field}}

在苹果设备上将会使用 Otoya,在 Windows 电脑上将会使用 Haruka。 在某些 TTS 实现中,可以指定不同的速度:

This would use Otoya when on an Apple device, and Haruka when on a Windows PC. Specifying a different speed is possible in some TTS implementations:

{{tts fr_FR speed=0.8:SomeField}}

速度和声音都是可选的,但必须包括语言。

Both speed and voices are optional, but the language must be included.

在 Mac 上,你可以自定义可用的声音:

On a Mac, you can customize the available voices:

  • 打开系统偏好设置

    Open the System Preferences screen.

  • 单击辅助功能

    Click on Accessibility.

  • 单击朗读内容

    Click on Speech.

  • 单击系统声音进行选择

    Click on the system voice dropdown, and choose Customize.

有些声音听起来比其他声音好,所以试着选择你喜欢的声音。请注意,Siri 语音只能由苹果应用程序使用。一旦你安装了新的语音,你需要重新启动 Anki 才能使用新的语音。

Some voices sound better than others, so experiment to choose the one you prefer. Please note that the Siri voice can only be used by Apple apps. Once you’ve installed new voices, you’ll need to restart Anki for the new voices to become available.

在 Windows 上,一些像 Cortana 这样的声音无法选择,因为微软不允许其他应用程序使用这些声音。

On Windows, some voices like Cortana can not be selected, as Microsoft does not make those voices available to other applications.

在挖空笔记类型中,你可以使用挖空过滤器让 Anki 只阅读省略的部分,如下所示:

On a cloze note type, you can make Anki read only the elided sections using the cloze-only filter, like so:

{{tts en_US:cloze-only:Text}}

Anki 2.1.29+ 和 AnkiMobile 2.0.65+ 支持挖空过滤器。

The cloze-only filter is supported in Anki 2.1.29+ and AnkiMobile 2.0.65+.

你可以在支持的平台上启用 Anki 的 TTS 功能,同时返回到 AnkiDroid 自己的方法在新窗口打开。在 AnkiDroid 支持{{tts:FieldName}}语法之前,它将把这些字段呈现为文本,而其他平台将呈现(重新)播放音频按钮。为了暂时解决平台之间的差异,我们可以在模板中使用以下内容:

You can enable Anki's TTS feature on supported platforms while falling back to AnkiDroid's own method. Until AnkiDroid supports the {{tts:FieldName}} syntax, it will render these fields as text, while other platforms will render a (re)play audio button. In order to temporarily fix this discrepancy between platforms, we can use the following in our templates:

<tts service="android" voice="en_US">{{Front}}</tts>

<span class="ankitts">{{tts en_US:Front}}</span>

<button
  class="ankidroidTtsButton"
  onclick="
AnkiDroidJS.ankiTtsSpeak('{{Front}}');"
>
  Play TTS
</button>

样式为:

/* Anki(桌面)TTS需要隐藏,因为AnkiDroid目前将其呈现为文本,
而不是像桌面那样的播放按钮。*/
.android .ankitts {
  display: none;
}

/* AnkiDroid tts按钮在其他平台上不起作用,
因为它使用JS API,因此应该隐藏它 */
html:not(.android) .ankidroidTtsButton {
  display: none;
}

多字段和静态文本发音

Text to Speech for multiple fields and static text

这个功能需要 Anki 2.1.50+,AnkiMobile 2.0.84+ 。AnkiDroid 目前不支持。

This feature requires Anki 2.1.50+ or AnkiMobile 2.0.84+ . AnkiDroid does not currently support this method.

[anki:tts lang=en_US] This text should be read. Here is {{Field1}} and {{Field2}}[/anki:tts]

This is other text on the template. It is outside of the tags so it should not be read.

特殊的字段

Special Fields

下面是模板中的特殊字段:

There are some special fields you can include in your templates:

The note's tags: {{Tags}}

The type of note: {{Type}}

The card's deck: {{Deck}}

The card's subdeck: {{Subdeck}}

The card's flag: {{CardFlag}}

The type of card ("Forward", etc): {{Card}}

The content of the front template
(only valid in back template): {{FrontSide}}

FrontSide 不会自动播放卡正面的任何音频。如果你希望在卡的正面和背面自动播放相同的音频,则还需要手动在背面包含音频字段。

FrontSide will not automatically play any audio that was on the front side of the card. If you wish to have the same audio play automatically on both the front and back of the card, you’ll need to manually include the audio fields on the back as well.

与其他字段一样,特殊字段名区分大小写-例如,你必须使用{{Tags}}而不是{{tags}}

As with other fields, special field names are case sensitive - you must use {{Tags}} rather than {{tags}} for example.

提示字段

Hint Fields

可以在卡片的正面或背面添加一个字段,但在显示之前将其隐藏。我们称之为“提示字段”。在添加提示之前,请记住,在 Anki 中回答问题越容易,当你在现实生活中遇到这个问题时,你就越不可能记住它。在继续之前请阅读最低信息原则在新窗口打开”。

It’s possible to add a field to the front or back of a card, but make it hidden until you explicitly show it. We call this a 'hint field'. Before adding a hint, please bear in mind that the easier you make it to answer a question in Anki, the less likely you are to remember that question when you encounter it in real life. Please have a read about the 'minimum information principle' on https://super-memory.com/articles/20rules.htm before proceeding.

首先,如果你还没有添加字段来存储提示,则需要添加一个字段。如果你不确定如何执行此操作,请参阅字段部分。

First, you’ll need to add a field to store the hint in if you have not already. Please see the fields section if you’re not sure how to do this.

假设你已经创建了一个名为 MyField 的字段,你可以告诉 Anki 将其包含在卡上,但默认情况下,通过在模板中添加以下内容来隐藏它:

Assuming you’ve created a field called MyField, you can tell Anki to include it on the card but hide it by default by adding the following to your template:

{{hint:MyField}}

这将显示一个标记为“显示提示”的链接;当你单击它时,该字段的内容将显示在卡片上。(如果 MyField 为空,则不会显示任何内容。)

This will show a link labeled “show hint”; when you click it, the content of the field will be displayed on the card. (If MyField is empty, nothing will be shown.)

如果你在问题上显示提示,然后显示答案,提示将再次隐藏。如果希望在显示答案时始终显示提示,则需要从后台模板中删除{{FrontSide}},然后手动添加要显示的字段。

If you show the hint on the question and then reveal the answer, the hint will be hidden again. If you want to have the hint always revealed when the answer is shown, you will need to remove {{FrontSide}} from your back template and manually add the fields you wish to appear.

当前无法将提示字段用于音频  —  无论你是否点击了提示链接,音频都会播放。

It is not currently possible to use a hint field for audio — the audio will play regardless of whether you’ve clicked on the hint link.

如果你想自定义外观或行为,则需要自己实现提示字段。我们无法为此提供任何支持,但以下代码应该可以帮助你入门:

If you want to customize the appearance or behaviour, you’ll need to implement the hint field yourself. We can not provide any support for doing so, but the following code should get you started:

{{#Back}}
<a class=hint href="#"
onclick="this.style.display='none';document.getElementById('hint4753594160').style.display='inline-block';return false;">
Show Back</a><div id="hint4753594160" class=hint style="display: none">{{Back}}</div>
{{/Back}}

字典链接

Dictionary Links

你也可以使用字段替换来创建字典链接。想象一下,你正在学习一种语言,你最喜欢的在线词典允许你使用以下网址搜索文本:

You can also use field replacement to create dictionary links. Imagine you’re studying a language and your favourite online dictionary allows you to search for text using a web URL like:

http://example.com/search?q=myword

你可以通过在模板中执行以下操作来添加自动链接:

You could add an automatic link by doing the following in your template:

{{Expression}}

<a href="http://example.com/search?q={{Expression}}">check in dictionary</a>

上面的模板允许你在查看时单击链接来搜索每个笔记的表达式。但是有一个警告,所以请看下一节。

The template above would allow you to search for each note’s expression by clicking on the link while reviewing. There is a caveat however, so please see the next section.

HTML 去除

HTML Stripping

与模板一样,字段存储在 HTML 中。在上面的字典链接示例中,如果表达式包含没有任何格式的单词“myword”,那么 HTML 将是相同的:“myword“。但是,当你在字段中包含格式时,会包含额外的 HTML。例如,如果“myword”用粗体显示,那么实际的 HTML 将是“<b>myword</b>”

Like templates, fields are stored in HTML. In the dictionary link example above, if the expression contained the word "myword" without any formatting, then the HTML would be the same: "myword". But when you include formatting in your fields, extra HTML is included. If "myword" was bolded for example, the actual HTML would be "<b>myword</b>".

这可能会给字典链接之类的东西带来问题。在上面的示例中,dictionary 链接最终为:

This can present a problem for things like dictionary links. In the above example, the dictionary link would end up being:

<a href="http://example.com/search?q=<b>myword</b>">check in dictionary</a>

链接中多余的字符可能会混淆词典网站,你很可能得不到任何匹配项。

The extra characters in the link would likely confuse the dictionary site, and you’re likely not to get any matches.

为了解决这个问题,Anki 提供了在字段被替换时从字段中去除格式的功能。如果在字段名称前面加上text:,Anki 将不包含任何格式。因此,即使是格式化文本也能使用的词典链接是:

To solve this, Anki provides the ability to strip formatting from fields when they are replaced. If you prefix a field name with text:, Anki will not include any formatting. So a dictionary link that worked even with formatted text would be:

<a href="http://example.com/search?q={{text:Expression}}">check in dictionary</a>

从右到左文本

Right To Left Text

如果你使用的语言是从右到左的,你需要这样调整模板:

If you’re using a language that reads from right to left, you’ll need to adjust the template like so:

<div dir=rtl>{{FieldThatHasRTLTextInIt}}</div>

ruby 字符

Ruby Characters

一些语言通常使用文本上方的注释来显示字符的发音。这些注释被称为 ruby 字符。在日语中,这些被称为 振假名(furigana)

Some languages commonly use annotations above the text to display the pronunciation of characters. These annotations are known as ruby characters. In Japanese, these are known as furigana.

在 Anki 中,可以使用以下语法显示 ruby 字符:

In Anki, you can display ruby characters by using the following syntax:

Text[Ruby]

假设上面的文本是 MyField 字段。默认情况下,如果你只使用{{Myfield}},该字段将按原样显示。要将 ruby 字符正确定位在文本上方,请在模板中使用 furigana 筛选器,如下所示:

Suppose the text above is written in MyField. By default, if you simply use {{Myfield}}, the field will be displayed as is. To properly position the ruby characters above the text, use the furigana filter in the templates like so:

{{furigana:MyField}}

示例:

FieldReplacements-1


注意第三个示例在字符前的空格,这对于指定 ruby 文本仅应用于该字符是必要的。如果没有空格,ruby 文本将放错位置,位于字符,如第四个示例所示。

Notice how the third example has a space before the character. This is necessary to specify that the ruby text applies only to that character. If there was no space, the ruby text will be misplaced above the の character, as shown in the fourth example.

其他 Ruby 字符过滤器

Additional Ruby Character Filters

除了furigana过滤器,你还可以使用kanakanji过滤器只显示 ruby 文本的某些部分。假名过滤器将只显示 ruby 文本,而汉字过滤器将完全删除 ruby 文本。

In addition to the furigana filter, you can also only show certain parts of the ruby text, with the kana and kanji filters. The kana filter will only show the ruby text, while the kanji filter removes the ruby text entirely.

FieldReplacements-2


这些名字又是从日语借来的。kana一词代表用来描述单词发音的语音系统,而kanji一词则代表其汉字。

These names are again, borrowed from Japanese. The term kana represents the phonetic system used to describe how words are pronounced, whereas the term kanji represents its Chinese characters.

媒体资源和 LaTeX

Media & LaTeX

Anki 不会扫描模板中的媒体引用,因为这样做很慢。这对在模板中包含媒体有影响。

Anki does not scan templates for media references, because it is slow to do so. This has implications for including media on the template.

静态音频/图片

Static Sounds/Images

如果你希望在你的卡片上包含每张卡片相同的图像或声音(例如,每张卡片顶部的公司标志):

If you wish to include images or sounds on your cards that are the same for every card (eg, a company logo at the top of each card):

  1. 重命名该文件,使其以下划线开始,例如_logo.jpg。下划线告诉 Anki 该文件由模板使用,应在共享牌组时导出该文件。

    Rename the file so it starts with an underscore, e.g _logo.jpg. The underscore tells Anki that the file is used by the template and it should be exported when sharing the deck.

  2. 在正面或背面模板上添加对媒体的引用,如:

    Add a reference to the media on your front or back template, like:

<img src="_logo.jpg">

字段引用

Field References

不支持对字段的媒体引用。它们可能在复习期间显示,也可能不显示,在检查未使用的媒体资源、导入/导出等时不起作用。不起作用的示例:

Media references to fields are not supported. They may or may not display during review, and will not work when checking for unused media, importing/exporting, and so on. Examples that won’t work:

<img src="{{Expression}}.jpg">

[sound:{{Word}}]

[latex]{{Field 1}}[/latex]

相反,你应该在字段中包含媒体引用。有关详细信息,请参阅导入部分。

Instead, you should include the media references in the field. Please see the importing section for more information.

检查你的答案

Checking Your Answer

你可以在 YouTube 上观看视频在新窗口打开

You can watch a video about this feature on YouTube.

检查答案的最简单的方法是点击添加卡片界面左上角的“Basic”,并且选择“Basic (type in the answer)”。

The easiest way to check your answer is to click "Basic" at the top left of the card adding screen, and select "Basic (type in the answer)".

如果你已经下载了一个共享卡片组,并想用它键入答案,你可以修改它的卡片模板。如果它有一个模板,如:

If you have downloaded a shared deck and would like to type in the answer with it, you can modify its card template. If it has a template like:

{{Native Word}}

{{FrontSide}}

<hr id=answer>

{{Foreign Word}}

要键入单词并检查你是否正确,你需要编辑你的前置模板,使其看起来如下:

To type in the foreign word and check if you are correct, you need to edit your front template so that it looks like this:

{{Native Word}}
{{type:Foreign Word}}

请注意,我们在要比较的字段前面添加了type:。由于 FrontSide 在卡片的背面,因此类型回答框也将出现在背面。

Note that we have added type: in front of the field we want to compare. Since FrontSide is on the back of the card, the type answer box will appear on the back as well.

复习时,Anki 会显示一个文本框,你可以在其中键入答案,点击Enter键或显示答案后,Anki 将向你显示哪些部分是对的,哪些部分是错的。文本框的字体大小将是你为该字段配置的大小(编辑时通过字段按钮)。

When reviewing, Anki will display a text box where you can type in the answer, and upon hitting Enter or showing the answer, Anki will show you which parts you got right and which parts you got wrong. The text box’s font size will be the size you configured for that field (via the “Fields” button when editing).

这个功能不会改变卡片的回答方式,所以你仍然可以决定你记得好不好。

This feature does not change how the cards are answered, so it’s still up to you to decide how well you remembered or not.

一张卡片上只能使用一个输入答案。如果你多次添加上述文本,它将不起作用。它也只支持单行,因此对于与由多行组成的字段进行比较没有用处。

Only one typing comparison can be used on a card. If you add the above text multiple times, it will not work. It also only supports a single line, so it is not useful for comparing against a field that is comprised of multiple lines.

Anki 使用等宽字体进行答案比较,以便“提供的”和“正确的”部分对齐。如果你希望覆盖答案比较的字体,可以将以下内容放在样式部分的底部:

Anki uses a monospaced font for the answer comparison so that the “provided” and “correct” sections line up. If you wish to override the font for the answer comparison, you can put the following at the bottom of your styling section:

code#typeans { font-family: "myfontname"; }

这将影响以下用于答案比较的 HTML:

Which will affect the following HTML for the answer comparison:

<code id=typeans>...</code>

高阶可以使用 css 类“typeGood”、“typeBad”和“typeMissed”覆盖默认的类型答案颜色。AnkiMobile 支持“typeGood”和“typeBad”,但不支持“typeMissed”。

Advanced users can override the default type-answer colors with the css classes 'typeGood', 'typeBad' and 'typeMissed'. AnkiMobile supports 'typeGood' and 'typeBad', but not 'typeMissed'.

如果你想覆盖默认输入框文字的大小,并且不想通过字段对话框改变,你可以用以下的样式进行覆盖:

If you wish to override the size of the typing box and don’t want to change the font in the Fields dialog, you can override the default inline style using !important, like so:

#typeans { font-size: 50px !important; }

也可以输入挖空卡片的答案。要做到这一点,请将{{type:cloze:Text}}添加到正面和背面的模板中,这样后面看起来像这样:

It is also possible to type in the answer for cloze deletion cards. To do this, add {{type:cloze:Text}} to both the front and back template, so the back looks something like this:

{{cloze:Text}}
{{type:cloze:Text}}
{{Extra}}

注意,由于挖空类型不使用 FrontSide,所以必须将其添加到挖空笔记的正面和背面。

Note that since the cloze type does not use FrontSide, this must be added to both sides on a cloze note type.

如果有多个部分被挖空,你可以用逗号分隔文本框中的答案。

If there are multiple sections elided, you can separate the answers in the text box with a comma.

键入答案框不会出现在浏览窗口的“预览”对话框中。当你在卡片类型窗口中查看或查看预览时,它们将显示出来。

Type answer boxes will not appear in the "preview" dialog in the browser. When you review or look at the preview in the card types window, they will display.

当你在 ankiweb.net在新窗口打开 上学习你的卡片时,键入答案框将不会显示。

Type answer boxes will not be displayed when you review your cards on ankiweb.net.