【问题标题】:Typo3: page link in menu using value from custom recordTypo3:菜单中的页面链接使用自定义记录中的值
【发布时间】:2015-01-26 15:02:51
【问题描述】:

我有:

  • 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
                }
                ...

【问题讨论】:

    标签: menu hyperlink field typo3 record


    【解决方案1】:

    我可以直接在用户函数中访问页面ID:

    打字稿:

    typolink.userFunc = user_mcfazabosOnCurrentPage->main
    

    PHP:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-11
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 2016-08-02
      • 2017-01-27
      相关资源
      最近更新 更多