繁体   English   中英

Typo3:菜单中的页面链接使用自定义记录中的值

[英]Typo3: page link in menu using value from custom record

我有 :

  • 3级菜单
  • 来自名为“ tx_products_domain_model_product”的表的自定义记录
  • 产品具有一个名为“ url_alias”的字段

在该菜单的任何页面上,我都可以有一条产品记录。 对于具有产品记录的页面,我希望链接看起来像:

http://www.sitedomain.com/<url_alias>

可以用打字稿完成吗?

编辑

看起来很难使用错字来完成所有这些操作,因此我正在使用userFunc。 我正在检查是否有带有商店ID的产品记录,并想返回该商店ID。 如果不是,则返回当前菜单页面UID。 问题是,如何将菜单页面UID作为参数传递给userFunc?

class user_productsOnCurrentPage
{
    function main( $content, $conf )
    {
        if ( TYPO3_MODE !== 'FE' )
        {
            return FALSE;
        }

        $product = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
                'shop_id', 'tx_products_domain_model_product', 'pid=' . $conf['currentPageId'] . ' AND deleted=0 AND hidden=0' );

        if ( is_array( $product ) && ! empty( $product ['shop_id'] ) )
        {
            return $product ['shop_id'];
        }

        return $conf['currentPageId'];
    }
}

菜单:

lib.mainMenu = HMENU
lib.mainMenu {
    ...
    1 = TMENU
    1 {
        ...
        NO = 1
        NO {
            ...
            # show direct url for external links
            doNotLinkIt = 1
            stdWrap.cObject = CASE
            stdWrap.cObject {
                key.field = doktype
                default = TEXT
                default {
                    field = nav_title // title

                    typolink.parameter.cObject = USER
                    typolink.parameter.cObject {
                        userFunc = user_productsOnCurrentPage->main
                        currentPageId = ?????
                    }

                    typolink.wrap = |<span><strong></strong></span>
                    typolink.ATagBeforeWrap = 1
                    stdWrap.htmlSpecialChars = 1
                }
                ...

我可以直接在用户功能中访问页面ID:

Typo脚本:

typolink.userFunc = user_mcfazabosOnCurrentPage->main

PHP:

$pageId = $this->cObj->getFieldVal( 'uid' );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM