0

您好 Processwire 的粉丝们,

我在 Processwire 中搜索更改我自己的 url-route 的解决方案。这是我在 Processwire 中的模板结构:

/categories (tpl_style_categories_parent.php)
    /cat1 (tpl_style_categories.php)
    /cat2 (tpl_style_categories.php)

现在的 url 是 categories/cat1 但我只想要 /cat1 作为 url。我怎样才能做到这一点?

4

1 回答 1

3

最好的方法是在 tpl_style_categories_parent 的父级上启用Url Segments(在您提供的结构上不可见)以捕获类别名称,并呈现相应页面的内容。该页面模板上的非常简化的代码(此处不可见):

if($input->urlSegment1) {

  $name = $sanitizer->name($input->urlSegment1);
  $category_page = $pages->get("template=tpl_style_categories, name={$name}");

  echo $category_page->render();

} else {

  // normal code for the template

}

请务必阅读该链接中的所有内容,以了解使用 Url Segments 的最佳实践

于 2016-10-10T16:50:25.090 回答