# reference

WXML provides two file referencesimportandinclude.

# import

ImportAtemplatedefined by the object file can be used in this file, such as:

Atemplateis defined in item.wxml calleditem:

<!-- item.wxml -->
<template name="item">
  <text>{{text}}</text>
</template>

Reference item.wxml in index.wxml, you can use theitemtemplate:

<import src="item.wxml"/>
<template is="item" data="{{text: 'forbar'}}"/>

# Scope of import

Import has the concept of scope, that is, only the template defined in the target file will be imported, not the template of the target file import.

For example: C import B, B import A, in C you can use B definedtemplate, in B you can use A defined `` template, but C cannot use A'stemplate [(`)] .

<!-- A.wxml -->
<template name="A">
  <text> A template </text>
</template>
<!-- B.wxml -->
<import src="a.wxml"/>
<template name="B">
  <text> B template </text>
</template>
<!-- C.wxml -->
<import src="b.wxml"/>
<template is="A"/>  <!-- Error! Can not use tempalte when not import A. -->
<template is="B"/>

# include

IncludeAn object file may be added to ````` include' ` include'

<!-- index.wxml -->
<include src="header.wxml"/>
<view> body </view>
<include src="footer.wxml"/>
<!-- header.wxml -->
<view> header </view>
<!-- footer.wxml -->
<view> footer </view>