首页 > 解决方案 > In kitsune, how to create a URL format of a details page of an entity without using k-dl?

问题描述

I am trying to create a ecommerce website in kitsune. I do not want to use the _kid value in k-dl. For example, the typical way to do it is -

k-dl="/product/[[product.name.urlencode()]]/[[product.code]]/[[product._kid]]"

If i do not want to use the _kid as its a long GUID. I would like to use code as its unique for every product as the identifier of the specific product.

When i define the k-dl as below it gives me an error that i must use _kid in the URL format:

k-dl="/product/[[product.name.urlencode()]]/[[product.code]]"

标签: serverless

解决方案


在 kitsune 中实现对象详细信息页面 URL 的理想方法是具有唯一 id,即_kid以及k-object以获得最佳性能,因为 kitsune 中的对象由_kid唯一标识,它是自动生成的 kitsune id .

但是,是的,有另一种方法可以在没有 kitsune 唯一 ID (_kid) 的情况下实现对象详细信息页面。

如果您想从您的角度维护对象的唯一性,您可以在 kitsune 对象中创建任何唯一字段并如下使用它。因此,如果您使用 k-object,_kid 是必需的,您需要从页面中删除 k-object 属性。

假设product.code是您从K-Admin维护的唯一字段,您可以使用如下的k-dl

<head k-dl="/product/[[product.name.urlencode()]]/[[product_code_param]]">

这里[[product_code]]是来自 URL 的动态变量,请确保传递正确的产品代码值以生成 URL。

现在你可以通过使用 k-repeat 循环来获得唯一的对象,如下所示

<div k-repeat="[[product in business.products]]">
  <div k-show="[[product.code == product_code_param]]"> <!--this will only render if the product code is matching with the url param-->
  
    <p>[[product.name]]</p>
  
  </div>
</div>


推荐阅读