我试图给2个内容类型相同的单一slu in in bolt。它们都应该具有相同的字段和相同的模板。此时,我使用record_template:
标记为每种内容类型设置默认模板。
vervolgpagina:
name: vervolgpagina
singular_slug: graszoden
singular_name: vervolg
fields:
titel:
type: text
class: large
group: Content
slug:
type: slug
uses: titel
group: Content
body:
type: html
height: 500px
group: Content
meta_keywords:
type: text
group: SEO
label: "Meta keywords"
meta_description:
type: textarea
height: 50px
group: SEO
label: "Meta description"
record_template: vervolgpagina.twig
graszoden:
name: graszoden
singular_slug: graszoden
singular_name: gras
fields:
titel:
type: text
class: large
group: Content
slug:
type: slug
uses: titel
group: Content
body:
type: html
height: 500px
group: Content
meta_keywords:
type: text
group: SEO
label: "Meta keywords"
meta_description:
type: textarea
height: 50px
group: SEO
label: "Meta description"
record_template: vervolgpagina.twig
所以,如果我只是放入两种内容类型之一并添加一个页面,那么它
将我重定向到/graszoden/vervolgpagina
所以如果我添加secont内容类型并向其添加另一个页面/graszoden/randomexample
现在发生了什么。是那个工作得很好的页面。 ERROR 404说,另一页给出了一个错误,“没有指定list.twig文件。”
有没有办法在cms中用其他名称两次显示内容类型?或者有没有办法给两个内容类型相同的单一slug?
提前完成,
答案 0 :(得分:2)
不,你不能。如果你有两个具有相同slug和相同字段的contenttypes,它应该只是一个CT。
也许您可能需要的是"分组分类",请参阅taxonomy.yml中的示例。
答案 1 :(得分:1)
在使用树枝进行更多螺栓项目后,我得到了一些其他解决方案。
如果您想多次使用单数slu will,您将被迫创建一个列表页面。但有了这个你就不必了。只需创建一个本地扩展并填写此答案末尾突出显示的部分。
Link to sourcecode 还没有自述文件。但我希望这里的解释足够好。
这是扩展文件代码(此代码完全是所有功能,您必须为此创建一个本地扩展才能工作):
class MatchAllController
{
/**
* The bolt application
*
* @var
*/
protected $app;
/**
* The path to the config.yml
*
* @var string
*/
protected $configPath = __DIR__ . '/../../config/config.yml';
public function matchAll(Request $request, $slug, Application $application)
{
$this->app = $application;
// var_dump($this->getConfig());die;
$contentTypes = ['provincies', 'vervolg'];
foreach($contentTypes as $contentType)
{
if(null !== $result = $this->record($request, $contentType, $slug)) {
return $result;
}
}
$this->abort(Response::HTTP_NOT_FOUND, "Page $slug not found.");
return null;
}
protected function getConfig()
{
return Yaml::parse(file_get_contents($this->configPath));
}
public function record(Request $request, $contenttypeslug, $slug = '')
{
$contenttype = $this->getContentType($contenttypeslug);
// Perhaps we don't have a slug. Let's see if we can pick up the 'id', instead.
if (empty($slug)) {
$slug = $request->get('id');
}
$slug = $this->app['slugify']->slugify($slug);
// First, try to get it by slug.
$content = $this->getContent($contenttype['slug'], ['slug' => $slug, 'returnsingle' => true, 'log_not_found' => !is_numeric($slug)]);
if (!$content && is_numeric($slug)) {
// And otherwise try getting it by ID
$content = $this->getContent($contenttype['slug'], ['id' => $slug, 'returnsingle' => true]);
}
// No content, no page!
if (!$content) {
return null;
}
// Then, select which template to use, based on our 'cascading templates rules'
$template = $this->templateChooser()->record($content);
// Setting the canonical URL.
if ($content->isHome() && ($template === $this->getOption('general/homepage_template'))) {
$url = $this->app['resources']->getUrl('rooturl');
} else {
$url = $this->app['resources']->getUrl('rooturl') . ltrim($content->link(), '/');
}
$this->app['resources']->setUrl('canonicalurl', $url);
// Setting the editlink
$this->app['editlink'] = $this->generateUrl('editcontent', ['contenttypeslug' => $contenttype['slug'], 'id' => $content->id]);
$this->app['edittitle'] = $content->getTitle();
// Make sure we can also access it as {{ page.title }} for pages, etc. We set these in the global scope,
// So that they're also available in menu's and templates rendered by extensions.
$globals = [
'record' => $content,
$contenttype['singular_slug'] => $content,
];
return $this->render($template, [], $globals);
}
/**
* Get the contenttype as an array, based on the given slug.
*
* @param string $slug
*
* @return boolean|array
*/
protected function getContentType($slug)
{
return $this->storage()->getContentType($slug);
}
/**
* Returns the Entity Manager.
*
* @return \Bolt\Storage\EntityManager
*/
protected function storage()
{
return $this->app['storage'];
}
/**
* Shortcut to abort the current request by sending a proper HTTP error.
*
* @param integer $statusCode The HTTP status code
* @param string $message The status message
* @param array $headers An array of HTTP headers
*
* @throws HttpExceptionInterface
*/
protected function abort($statusCode, $message = '', array $headers = [])
{
$this->app->abort($statusCode, $message, $headers);
}
/**
* Shortcut for {@see \Bolt\Legacy\Storage::getContent()}
*
* @param string $textquery
* @param array $parameters
* @param array $pager
* @param array $whereparameters
*
* @return \Bolt\Legacy\Content|\Bolt\Legacy\Content[]
*
* @see \Bolt\Legacy\Storage::getContent()
*/
protected function getContent($textquery, $parameters = [], &$pager = [], $whereparameters = [])
{
return $this->storage()->getContent($textquery, $parameters, $pager, $whereparameters);
}
/**
* Return the Bolt\TemplateChooser provider.
*
* @return \Bolt\TemplateChooser
*/
protected function templateChooser()
{
return $this->app['templatechooser'];
}
/**
* Shortcut for {@see UrlGeneratorInterface::generate}
*
* @param string $name The name of the route
* @param array $params An array of parameters
* @param int $referenceType The type of reference to be generated (one of the constants)
*
* @return string
*/
protected function generateUrl($name, $params = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
{
/** @var UrlGeneratorInterface $generator */
$generator = $this->app['url_generator'];
return $generator->generate($name, $params, $referenceType);
}
/**
* Renders a template
*
* @param string $template the template name
* @param array $variables array of context variables
* @param array $globals array of global variables
*
* @return \Bolt\Response\BoltResponse
*/
protected function render($template, array $variables = [], array $globals = [])
{
return $this->app['render']->render($template, $variables, $globals);
}
}
这是一个新的启动项目。唯一可变的是这部分
public function matchAll(Request $request, $slug, Application $application)
{
$this->app = $application;
//Fill your costum routes in here
$contentTypes = ['VARIABLE SINGULAR SLUG', 'VARIABLE SINGULAR SLUG 2'];
foreach($contentTypes as $contentType)
{
if(null !== $result = $this->record($request, $contentType, $slug)) {
return $result;
}
}
$this->abort(Response::HTTP_NOT_FOUND, "Page $slug not found.");
return null;
}
$ contentTypes = [' VARIABLE SINGULAR SLUG',' VARIABLE SINGULAR SLUG 2'];
这段特殊的代码是你填写你想要使用的单一的slug。它可以包含无限的slu
希望以后可以帮助别人。快乐的编码!