# Importing
FXML provides two methods for file importing: import and include.
# 1. import
import allows the use of template defined in the target file within the current file, for example:
Define a template named item in item.fxml:
<!-- item.fxml -->
<template name="item">
<text>{{text}}</text>
</template>
After importing item.fxml in index.fxml, you can use the item template:
<import src="item.fxml"/>
<template is="item" data="{{text: 'forbar'}}"/>
# 2. Scope of import
Import has the concept of scope, meaning it only imports the template defined in the target file, and does not import templates imported by the target file.
For example: C imports B, B imports A. In C, you can use the template defined in B, and in B you can use the template defined in A, but C cannot use the template defined in A.
<!-- A.fxml -->
<template name="A">
<text> A template </text>
</template>
<!-- B.fxml -->
<import src="a.fxml"/>
<template name="B">
<text> B template </text>
</template>
<!-- C.fxml -->
<import src="b.fxml"/>
<template is="A"/> <!-- Error! Can not use tempalte when not import A. -->
<template is="B"/>
# 3. include
include imports the entire code of the target file except for <template/> and <fts/>, essentially copying it to the include location, for example:
<!-- index.fxml -->
<include src="header.fxml"/>
<view> body </view>
<include src="footer.fxml"/>
<!-- header.fxml -->
<view> header </view>
<!-- footer.fxml -->
<view> footer </view>