Skip to content

tpl

tpl is an enhanced version of the file function, providing simple template engine functionality.

Rule Syntax

txt
pattern tpl://value [filters...]
ParametersDescriptionDetailed Documentation
patternExpression to match request URLsMatch Pattern Documentation
valueOperation content, supports the following types:
• Directory/File Path
• Remote URL
• Inline/Embedded/Values content
Operation Instruction Documentation
filtersOptional filters, supports matching:
• Request URL/Method/Header/Content
• Response Status Code/Header
Filter Documentation

Template Rules

  1. Value format: {key} or
  2. key: A property in the request parameters

Mock JSONP

  1. Local File /User/xxx/test.js
js
{callback}({
  ec: 0
});
  1. Rule Configuration
txt
https://www.example.com/test/tpl tpl:///User/xxx/test.js

# Supports remote URLs
# pattern tpl://https://example.com/template
  1. Request https://www.example.com/test/tpl?callback=test Returns:
txt
test({
  ec: 0
});

For other functions, refer to file