Azure API 管理中的产品模板Product templates in Azure API Management

通过 Azure API 管理,用户能够使用一组用于配置内容的模板自定义开发人员门户页的内容。Azure API Management provides you the ability to customize the content of developer portal pages using a set of templates that configure their content. 使用 DotLiquid 语法和所选编辑器(例如 DotLiquid for Designers),以及提供的一组本地化字符串资源字形资源页面控件,即可根据这些模板的使用需要非常灵活地配置页面内容。Using DotLiquid syntax and the editor of your choice, such as DotLiquid for Designers, and a provided set of localized String resources, Glyph resources, and Page controls, you have great flexibility to configure the content of the pages as you see fit using these templates.

本部分中的模板可用于自定义开发人员门户中产品页面的内容。The templates in this section allow you to customize the content of the product pages in the developer portal.

备注

示例默认模板包含在后续文档中,但是会因持续改进而有所更改。Sample default templates are included in the following documentation, but are subject to change due to continuous improvements. 通过导航到所需单个模板,可在开发人员门户中查看实时的默认模板。You can view the live default templates in the developer portal by navigating to the desired individual templates. 如需详细了解如何使用模板,请参阅如何使用模板自定义 API 管理开发人员门户For more information about working with templates, see How to customize the API Management developer portal using templates.

备注

此文档内容与旧开发人员门户有关。This documentation content is about the legacy developer portal. 请参阅以下文章,了解有关新开发人员门户的内容:Refer to the following articles for content about the new developer portal:

可用性Availability

重要

此功能在 API 管理的“高级”、“标准”、“基本”和“开发人员”层中可用。This feature is available in the Premium, Standard, Basic and Developer tiers of API Management.

产品列表Product list

产品列表模板可用于自定义开发人员门户中产品列表页的正文。The Product list template allows you to customize the body of the product list page in the developer portal.

产品列表Products list

默认模板Default template

<search-control></search-control>  
<div class="row">  
    <div class="col-md-9">  
        <h2>{% localized "ProductsStrings|PageTitleProducts" %}</h2>  
    </div>  
</div>  
<div class="row">  
    <div class="col-md-12">  
    {% if products.size > 0 %}  
    <ul class="list-unstyled">  
    {% for product in products %}  
        <li>  
            <h3><a href="/products/{{product.id}}">{{product.title}}</a></h3>  
            {{product.description}}  
        </li>     
    {% endfor %}  
    </ul>  
    <paging-control></paging-control>  
    {% else %}  
    {% localized "CommonResources|NoItemsToDisplay" %}  
    {% endif %}  
    </div>  
</div>  

控制Controls

Product list 模板可使用以下页面控件The Product list template may use the following page controls.

数据模型Data model

属性Property 类型Type 说明Description
分页Paging 分页实体。Paging entity. 产品集合的分页信息。The paging information for the products collection.
筛选Filtering 筛选实体。Filtering entity. 产品列表页的筛选信息。The filtering information for the products list page.
产品Products 产品实体的集合。Collection of Product entities. 对当前用户可见的产品。The products visible to the current user.

示例模板数据Sample template data

{  
    "Paging": {  
        "Page": 1,  
        "PageSize": 10,  
        "TotalItemCount": 2,  
        "ShowAll": false,  
        "PageCount": 1  
    },  
    "Filtering": {  
        "Pattern": null,  
        "Placeholder": "Search products"  
    },  
    "Products": [  
        {  
            "Id": "56f9445ffaf7560049060001",  
            "Title": "Starter",  
            "Description": "Subscribers will be able to run 5 calls/minute up to a maximum of 100 calls/week.",  
            "Terms": "",  
            "ProductState": 1,  
            "AllowMultipleSubscriptions": false,  
            "MultipleSubscriptionsCount": 1  
        },  
        {  
            "Id": "56f9445ffaf7560049060002",  
            "Title": "Unlimited",  
            "Description": "Subscribers have completely unlimited access to the API. Administrator approval is required.",  
            "Terms": null,  
            "ProductState": 1,  
            "AllowMultipleSubscriptions": false,  
            "MultipleSubscriptionsCount": 1  
        }  
    ]  
}  

产品Product

产品模板可用于自定义开发人员门户中产品页的正文。The Product template allows you to customize the body of the product page in the developer portal.

开发人员门户产品页Developer portal product page

默认模板Default template

<h2>{{Product.Title}}</h2>  
<p>{{Product.Description}}</p>  
  
{% assign replaceString0 = '{0}' %}  
  
{% if Limits and Limits.size > 0 %}  
<h3>{% localized "ProductDetailsStrings|WebProductsUsageLimitsHeader"%}</h3>  
<ul>  
  {% for limit in Limits %}  
  <li>{{limit.DisplayName}}</li>  
  {% endfor %}  
</ul>  
{% endif %}  
  
{% if apis.size > 0 %}  
<p>  
  <b>  
    {% if apis.size == 1 %}  
    {% capture apisCountText %}{% localized "ProductDetailsStrings|TextblockSingleApisCount" %}{% endcapture %}  
    {% else %}  
    {% capture apisCountText %}{% localized "ProductDetailsStrings|TextblockMultipleApisCount" %}{% endcapture %}  
    {% endif %}  
  
    {% capture apisCount %}{{apis.size}}{% endcapture %}  
    {{ apisCountText | replace : replaceString0, apisCount }}  
  </b>  
</p>  
  
<ul>  
  {% for api in Apis %}  
  <li>  
    <a href="/docs/services/{{api.Id}}">{{api.Name}}</a>  
  </li>  
  {% endfor %}  
</ul>  
{% endif %}  
  
{% if subscriptions.size > 0 %}  
<p>  
  <b>  
    {% if subscriptions.size == 1 %}  
    {% capture subscriptionsCountText %}{% localized "ProductDetailsStrings|TextblockSingleSubscriptionsCount" %}{% endcapture %}  
    {% else %}  
    {% capture subscriptionsCountText %}{% localized "ProductDetailsStrings|TextblockMultipleSubscriptionsCount" %}{% endcapture %}  
    {% endif %}  
  
    {% capture subscriptionsCount %}{{subscriptions.size}}{% endcapture %}  
    {{ subscriptionsCountText | replace : replaceString0, subscriptionsCount }}  
  </b>  
</p>  
  
<ul>  
  {% for subscription in subscriptions %}  
  <li>  
    <a href="/developer#{{subscription.Id}}">{{subscription.DisplayName}}</a>  
  </li>  
  {% endfor %}  
</ul>  
{% endif %}  
{% if CannotAddBecauseSubscriptionNumberLimitReached %}  
<b>{% localized "ProductDetailsStrings|TextblockSubscriptionLimitReached" %}</b>  
{% elsif CannotAddBecauseMultipleSubscriptionsNotAllowed == false %}  
<subscribe-button></subscribe-button>  
{% endif %}  

控制Controls

Product list 模板使用以下页面控件The Product list template may use the following page controls.

数据模型Data model

属性Property 类型Type 说明Description
产品Product 产品Product 指定的产品。The specified product.
IsDeveloperSubscribedIsDeveloperSubscribed 布尔值boolean 当前用户是否订阅了此产品。Whether the current user is subscribed to this product.
SubscriptionStateSubscriptionState 数字number 订阅的状态。The state of the subscription. 可能的状态包括:Possible states are:

- 0 - suspended – 订阅被阻止,订阅服务器无法调用产品的任何 API。- 0 - suspended – the subscription is blocked, and the subscriber cannot call any APIs of the product.
- 1 - active – 订阅处于活动状态。- 1 - active – the subscription is active.
- 2 - expired – 订阅已达到其到期日期,因此已停用。- 2 - expired – the subscription reached its expiration date and was deactivated.
- 3 - submitted – 开发人员已提交订阅请求,但管理员尚未批准或拒绝该请求。- 3 - submitted – the subscription request has been made by the developer, but has not yet been approved or rejected.
- 4 - rejected – 管理员已拒绝订阅请求。- 4 - rejected – the subscription request has been denied by an administrator.
- 5 - cancelled – 开发人员或管理员已取消订阅。- 5 - cancelled – the subscription has been cancelled by the developer or administrator.
限制Limits 数组array 此属性已弃用,不应使用。This property is deprecated and should not be used.
DelegatedSubscriptionEnabledDelegatedSubscriptionEnabled 布尔值boolean 是否为此订阅启用了委派Whether delegation is enabled for this subscription.
DelegatedSubscriptionUrlDelegatedSubscriptionUrl 字符串string 委派的订阅 URL(如果启用了委派)。If delegation is enabled, the delegated subscription URL.
IsAgreedIsAgreed 布尔值boolean 如果产品有条款,当前用户是否已同意这些条款。If the product has terms, whether the current user has agreed to the terms.
订阅Subscriptions 订阅摘要实体的集合。Collection of Subscription summary entities. 对产品的订阅。The subscriptions to the product.
ApisApis API 实体的集合。Collection of API entities. 此产品中的 API。The APIs in this product.
CannotAddBecauseSubscriptionNumberLimitReachedCannotAddBecauseSubscriptionNumberLimitReached 布尔值boolean 当前用户是否符合订阅此产品的条件(考虑到订阅限制)。Whether the current user is eligible to subscribe to this product with regard to the subscription limit.
CannotAddBecauseMultipleSubscriptionsNotAllowedCannotAddBecauseMultipleSubscriptionsNotAllowed 布尔值boolean 当前用户是否符合订阅此产品的条件(考虑到是否允许多个订阅)。Whether the current user is eligible to subscribe to this product with regard to multiple subscriptions being allowed or not.

示例模板数据Sample template data

{  
    "Product": {  
        "Id": "56f9445ffaf7560049060001",  
        "Title": "Starter",  
        "Description": "Subscribers will be able to run 5 calls/minute up to a maximum of 100 calls/week.",  
        "Terms": "",  
        "ProductState": 1,  
        "AllowMultipleSubscriptions": false,  
        "MultipleSubscriptionsCount": 1  
    },  
    "IsDeveloperSubscribed": true,  
    "SubscriptionState": 1,  
    "Limits": [],  
    "DelegatedSubscriptionEnabled": false,  
    "DelegatedSubscriptionUrl": null,  
    "IsAgreed": false,  
    "Subscriptions": [  
        {  
            "Id": "56f9445ffaf7560049070001",  
            "DisplayName": "Starter  (default)"  
        }  
    ],  
    "Apis": [  
        {  
            "id": "56f9445ffaf7560049040001",  
            "name": "Echo API",  
            "description": null,  
            "serviceUrl": "http://echoapi.cloudapp.net/api",  
            "path": "echo",  
            "protocols": [  
                2  
            ],  
            "authenticationSettings": null,  
            "subscriptionKeyParameterNames": null  
        }  
    ],  
    "CannotAddBecauseSubscriptionNumberLimitReached": false,  
    "CannotAddBecauseMultipleSubscriptionsNotAllowed": true  
}  

后续步骤Next steps

如需详细了解如何使用模板,请参阅如何使用模板自定义 API 管理开发人员门户For more information about working with templates, see How to customize the API Management developer portal using templates.