## Template instances
一個模板實例對象代表文檔對模板的一次引入。模板實例可以用來獲取模板中的HTML元素,還可以給模板實例附加屬性,屬性會在模板響應式更新中保持,不會丟失。
在好幾個地方都可以獲取到模板實例對象:
1. 在`created`, `rendered`和 `destroyed`模板回調中,this指向模板實例
2. 事件處理器的第二個參數
3. 在Helper中,通過[`Template.instance()`](#template_instance)獲取模板實例
你可以選擇給模板實例附加屬性,來跟蹤模板相關的狀態。例如,當使用Google Maps API 時,你可以附加`map`對象到當前模板實例,這樣就可以在Helper和事件處理器中引用`map`對象。用[`onCreated`](#template_onCreated) 和 [`onDestroyed`](#template_onDestroyed)回調函數來執行初始化或清理工作。
### [_template_.findAll(selector)](#/basic/Blaze-TemplateInstance-findAll)
Client
Find all elements matching `selector` in this template instance.
#### Arguments
selector String
The CSS selector to match, scoped to the template contents.
`template.findAll`返回一個符合`selector`的DOM元素數組。也可以使用`template.$`,它的工作方式和JQuery的`$`函數一樣,但是只返回`template`內部的元素。
### [_template_.find(selector)](#/basic/Blaze-TemplateInstance-find)
Client
Find one element matching `selector` in this template instance.
#### Arguments
selector String
The CSS selector to match, scoped to the template contents.
`find`類似`findAll`但是只返回找到的第一個元素。和`findAll`一樣,`find`只返回模板內部的元素。