我正在尝试将 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
你的 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;
}
}
你可以在 userFunc 中使用 $_GET 吗?
尝试在您的用户功能中使用它
$pageId = $this->cObj->stdWrap($conf['page_id'], $conf['page_id.']);
在打字稿中使用它之后
page_id.cObject = TEXT
page_id.cObject.data = GP:category
这是适合我的解决方案。 通过 html 中的 cObject 传递你的论点(从流体或任何你想要的地方)。
<f:cObject typoscriptObjectPath="lib.categoryContent" >{category.uid}</f:cObject>
或
<f:cObject typoscriptObjectPath="lib.categoryContent" data="{category.uid}" />
打字稿:
# 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>
}
我被困在这里了!之前通过了所有解决方案,但我没有设法将变量从流体通过 cobj 传递到 userfunc。 usefunc 开始了,但我没有设法将任何动态设置的变量传递给它