我正在尝试将get参数发送到userFunc
以识别页面,但它似乎不起作用。这就是我所拥有的:
########## CATEGORY CONTENT ##########
lib.categoryContent = COA
lib.categoryContent {
10 < styles.content.get
10 {
select {
pidInList.cObject = USER
pidInList.cObject {
userFunc = Vendor\Provider\UserFunc\PageIdByAlias->getPageIdByAlias
alias = TEXT
alias.data = GP:category
}
}
}
wrap = <categoryContent><![CDATA[|]]></categoryContent>
}
在PHP中:
/**
* Returns page ID by alias
*
* @return int
*/
public function getPageIdByAlias($content, $conf)
{
$pageId = $this->pageRepository->getPageIdByAlias($conf["alias"]);
return $pageId;
}
我也尝试过:
alias.cObject = TEXT
alias.cObject.data = GP:category
但是,我只在PHP中获取字符串GP:category
。
我正在使用TYPO3 7.6.11
答案 0 :(得分:2)
您的TypoScript是正确的。但是,由于渲染被委托给用户函数,因此不会执行嵌套的TypoScript属性 - 这必须在您的自定义用户函数中执行。 ContentObjectRenderer
的实例会自动作为属性PageIdByAlias::$cObj
注入您的自定义类。
<?php
namespace Vendor\Provider\UserFunc;
class PageIdByAlias
{
/**
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
*/
public $cObj;
protected $pageRepository;
/**
* Returns page ID by alias
*
* @var string $content
* @var array $configuration
* @return int|string
**/
public function getPageIdByAlias($content, array $configuration = null)
{
$pageId = 0;
// apply stdWrap() rendering for property 'alias'
// 3rd argument defines a custom default value if property is not set
$alias = $this->cObj->stdWrapValue('alias', $configuration, null);
if ($alias !== null) {
$pageId = $this->pageRepository->getPageIdByAlias($alias);
}
return $pageId;
}
}
答案 1 :(得分:1)
你可以在userFunc中使用$ _GET吗?
答案 2 :(得分:1)
尝试在您的用户功能中使用它
$pageId = $this->cObj->stdWrap($conf['page_id'], $conf['page_id.']);
在typoscript
中使用它之后page_id.cObject = TEXT
page_id.cObject.data = GP:category
答案 3 :(得分:-1)
这是适合我的解决方案。 从html(来自流体或任何你想要的地方)传递cObject的参数。
<f:cObject typoscriptObjectPath="lib.categoryContent" >{category.uid}</f:cObject>
或者
<f:cObject typoscriptObjectPath="lib.categoryContent" data="{category.uid}" />
Typoscript:
# Set argument to the current.
lib.category = TEXT
lib.category{
current = 1
}
lib.categoryContent = USER
lib.categoryContent{
10 < styles.content.get
10 {
select {
pidInList.cObject = USER
pidInList.cObject {
userFunc = Vendor\Provider\UserFunc\PageIdByAlias->getPageIdByAlias
# Pass category id as argument
alias = TEXT
alias.value < lib.category
}
}
}
wrap = <categoryContent><![CDATA[|]]></categoryContent>
}