How to apply a different wrap in a TMENU for certain items only?

非 Y 不嫁゛ 提交于 2019-12-11 13:07:07

问题


In a TMENU, I would like to apply a special wrap to certain pages only.

So of

Home
-- This
-- That
-- Such
-----A
-----Thing

Only the page "Such" would have this wrap (with a special class or an icon for wrapItemsAndSub).

Ideally, this could be done from the page tree / from the CMS. Or by pid. But I think it's not possible to reach into the TMENU in an easy way? OptionSplit is not an option, as it's only a few special pages.

Can this be done and how?


回答1:


BTW: as pgampe said it can be of course done more universal with some checkbox or even dropdown when you select class name.

This is a short tutorial for checkbox. For this tutorial I assume the extension name is "t3_local"

STEP 1

In ext_tables.sql file add:

CREATE TABLE pages (
    tx_t3local_special tinyint(4) DEFAULT '0' NOT NULL,
}

Then go into Extension Manager into your extension and update database to create the new field in pages table.

STEP 2

In ext_tables.php file add:

$tempColumns = Array(
    'tx_t3local_special' => Array(
        'exclude' => 1,
        'label' => 'Some label for special',
        'config' => Array(
            'type' => 'check',
            'default' => 0
        )
    )

);

t3lib_div::loadTCA('pages');
t3lib_extMgm::addTCAcolumns('pages', $tempColumns, 1);
t3lib_extMgm::addToAllTCAtypes('pages', 'tx_t3local_special');

It is ready now to use in the backend. After you clear the TYPO3 cache you should see the checkbox in page properties. Now we must only use it to build our menu in frontend.

STEP 3

Now it all depends what do you want to do with this switch. Assuming that you want to add a class for li here is a little trick how to allow to use several such switches to accumulate different classes.

NO.wrapItemAndSub.stdWrap {
   prepend.cObject = LOAD_REGISTER
   prepend.cObject {

     special1class.cObject = TEXT
     special1class.cObject {
        value = special1-class
        if.isTrue.field = tx_t3local_special
      }
     special2class.cObject = TEXT
     special2class.cObject {
        value = special2-class
        if.isTrue.field = tx_t3local_special2
      }

   }
   append = TEXT
   append.value = <li class="clearfix {register:special1class} {register:special2class}">/li>
   append.insertData = 1
}

NOTE

As you now know how to add switches to page property you can also use them to turn off/on some functionality on page. For example I use such switch to turn on/off breadcrumbs for page. In this example the if checkbox is checked the breadcrumb of off.

For this working you must remember to add the field name to typo3conf/localconf.php file (or LocalConfiguration.php in 6.x)

$TYPO3_CONF_VARS['FE']['addRootLineFields'] .= ',tx_t3local_breadcrumb';

And the TS:

lib.breadcrumb = COA
lib.breadcrumb.stdWrap.if.isFalse.data = page:tx_t3local_breadcrumb
lib.breadcrumb {
...
...
...
}



回答2:


You must use CASE object here and apply that to property/wrap which has stdWrap. Look at this example.

NO {
  wrapItemAndSub.cObject  = CASE
  wrapItemAndSub.cObject  {
                key.field = uid

                default = TEXT
                default.value = <li>|</li>

                // for page uid = 99
                99 = TEXT
                99.value = <li class="special">|</li>

            }
}

You can use this way to every element that has stdWrap.



来源:https://stackoverflow.com/questions/18899573/how-to-apply-a-different-wrap-in-a-tmenu-for-certain-items-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!