Azure API 管理中的产品模板

通过 Azure API 管理,用户能够使用一组用于配置内容的模板自定义开发人员门户页面的内容。 使用 DotLiquid 语法和所选编辑器(例如 DotLiquid for Designers),以及提供的一组本地化字符串资源字形资源页面控件,即可根据这些模板的使用需要非常灵活地配置页面内容。

本部分中的模板允许你在开发人员门户中自定义产品页面的内容。

注释

示例默认模板包含在后续文档中,但是会因持续改进而有所更改。 通过导航到所需单个模板,可在开发人员门户中查看实时的默认模板。 如需详细了解如何使用模板,请参阅如何使用模板自定义 API 管理开发人员门户

注释

以下文档内容与已弃用的开发人员门户有关。 你可以像往常一样继续使用它,直到它在 2023 年 10 月停用,届时将从所有 API 管理服务中将其删除。 弃用的门户只会接收关键安全更新。 有关更多详细信息,请参阅以下文章:

适用于:开发人员 | 基本 | 标准 | 高级

产品列表

产品列表 模板允许你在开发人员门户中自定义产品列表页面的正文。

产品列表

默认模板

<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>  

控件

Product list 模板可使用以下页面控件

数据模型

财产 类型 说明
寻呼 分页实体。 产品集的分页信息。
筛选 筛选 实体。 产品列表页的筛选信息。
产品 Product 实体的集合。 当前用户可见的产品。

示例模板数据

{  
    "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  
        }  
    ]  
}  

产品

使用 产品 模板,可以在开发人员门户中自定义产品页面的正文。

开发人员门户产品页面

默认模板

<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 %}  

控件

Product list 模板可使用以下页面控件

数据模型

财产 类型 说明
产品 产品 指定的产品。
开发者是否已订阅 布尔型 当前用户是否订阅此产品。
订阅状态 (SubscriptionState) 数字 订阅的状态。 可能的状态包括:

- 0 - suspended – 订阅被阻止,订阅者无法调用产品的任何 API。
- 1 - active – 订阅处于活动状态。
- 2 - expired – 订阅已过期并已停用。
- 3 - submitted – 开发人员已发出订阅请求,但尚未获得批准或拒绝。
- 4 - rejected – 管理员拒绝了订阅请求。
- 5 - cancelled – 开发人员或管理员已取消订阅。
限制 数组 此属性已弃用,不应使用。
委托订阅已启用 布尔型 此订阅是否启用了 委托
委托订阅URL 字符串 如果启用了委派,则已委派的订阅 URL。
是否同意 布尔型 如果产品具有条款,则当前用户是否同意条款。
订阅 订阅摘要 实体的集合。 产品的订阅。
蜜蜂属 API 实体的集合。 此产品中的 API。
无法添加,因为已达到订阅数量限制 布尔型 当前用户是否符合订阅此产品的资格,考虑到订阅限制。
无法添加因为不允许多个订阅 布尔型 当前用户是否有资格在允许多个订阅时订阅此产品。

示例模板数据

{  
    "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  
}  

后续步骤

如需详细了解如何使用模板,请参阅如何使用模板自定义 API 管理开发人员门户