> For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/api/lynx-native-api/lynx-view/load-template.md.

# loadTemplate

APISummary
使用 [`LynxLoadMeta`](/zh/api/lynx-native-api/lynx-load-meta.md) 渲染 `LynxView`，是客户端加载 `Lynx` 模板的主入口。

## 语法

### Android

```java
public void loadTemplate(@NonNull LynxLoadMeta meta);
```

#### 参数说明

- `meta`: Lynx 模板加载元数据，开发者通过该数据结构指定模板加载的可选数据。

### iOS

```objc
- (void)loadTemplate:(nonnull LynxLoadMeta *)meta;
```

#### 参数说明

- `meta`: Lynx 模板加载元数据，开发者通过该数据结构指定模板加载的可选数据。

### Harmony

LynxView 包含以下成员：

- `url: String `: 模板文件路径。
- `buffer: ArrayBuffer`: 模板的二进制文件数据。
- `templateBundle: TemplateBundle`: 由模板的二进制文件数据预先解析的 [TemplateBundle](/zh/api/lynx-native-api/template-bundle.md) 对象。
- `metaData: MetaData`: 在首屏加载过程中由客户端指定的初始数据。
- `loadOption: LynxLoadOption`: 加载模板时的附加配置信息。

```typescript
@Entry
@Component
struct Index {
  private url: string = 'playground/main.lynx.bundle';
  private buffer: ArrayBuffer = getTemplateBuffer();
  private metaData = new MetaData(
    new TemplateData('{"text":"TD"}'),
    new TemplateData({ "theme": "Light" }));

  build() {
    Column() {
      LynxView({
        url: this.url,
        buffer: this.buffer,
        metadata: this.metaData,
      }).width('100%').height('100%');
    }
    .size({ width: '100%', height: '100%' })
  }
}
```

### Web

```typescript
const lynxView = document.createElement('lynx-view');
lynxView.url = 'path/to/your/template.bundle';
```

### Desktop (C++)

```cpp
void LoadTemplate(std::shared_ptr<lynx::pub::LynxLoadMeta> load_meta);
```

#### 参数说明

- `load_meta`: 用于提供模板 URL、二进制数据、模板包、初始数据和全局属性的加载元数据。

## 兼容性

**Compatibility Table**
**Query:** `lynx-native-api.lynx-view.load-template`

**Platform Support**

| Platform | Version Added | Notes |
|----------|---------------|-------|
| Android | 2.8 | - |
| iOS | 2.8 | - |
| HarmonyOS | 3.4 | - |
| Web | ✅ Yes | use the <code>url</code> property; ⚠️ Partial implementation |
| Clay macOS | 3.7 | - |
| Clay Windows | 3.7 | - |

**Description:** load a lynx template file by LynxView.

