简体   繁体   中英

Typo3: Simplest way to add a custom field to all tt_content in 6.2

I am using Typo3 6.2, which has Extension Builder installed in the back-end. I have never built an extension before and am not sure if I need to, but it could be necessary to do what I want.

I have a variety of content types on each page, nested inside of gridelements columns. I want to add a "Background colour" drop-down for all content elements that I can check for in typoscript and assign a class accordingly:

Goal HTML, where "green" and "dark" are the classes I want to add:

 <div class="row"> <-- gridelements
    <div class="column size2"> <-- gridelements

        <div class="module green"> <-- content element with green bg
            Some content: could be text, image, news content, etc.
        </div>

        <div class="module dark"> <-- content element with dark bg
            Some content: could be text, image, news content, etc.
        </div>

        <div class="module"> <-- content element with no bg selected
            Some content: could be text, image, news content, etc.
        </div>

    </div>
</div>

Here's approximately how I expect to be looking for the "Background colour" field in the typoscript:

if{
    value = 1 <--- equal to the value of the drop-down
    equals.field = background_colour <--- the name of my custom field
}
//Then add the class to the mark-up

I've found a handful of tutorials, none of which really tell me how to do this. This one tells me how to create a whole new content element type, and also uses Kickstarter rather than Extension Builder: http://castironcoding.com/resources/our-blog/sp/view/show/post/reason-6-for-choosing-typo3-custom-content-elements-and-extbase-again-part-23.html?tx_cicblog_list%5Bcontroller%5D=Posts&cHash=13d15edce9ae768be7dd36a140811b82

This one tells me how to extend only News items: http://docs.typo3.org/typo3cms/extensions/news/latest/Main/Tutorial/ExtendingNews/

Does anyone know of a tutorial in English, or can explain a bit, how it would work to simply add an additional selectable field to all content elements?

You can use TypoScript to do something like this. Add this to your page.ts config, then you can select it via "appearance/layout"

TCEFORM.tt_content.section_frame {
    removeItems = 1,5,6,10,11,12,20,21,66
    addItems {
        100 = Module Green
        110 = Module Dark
    }
}

in the your main TypoScript setup, you have to add:

tt_content.stdWrap.innerWrap.cObject {
    100 =< tt_content.stdWrap.innerWrap.cObject.default
    100.20.10.value = module green

    100 =< tt_content.stdWrap.innerWrap.cObject.default
    100.20.10.value = module dark
}

the second one should give you the class names u need for your HTML.

If you really cannot reuse an existing field, try the extension kickstarter instead. You can find a 6.2 compatible version at: https://github.com/mneuhaus/TYPO3-Kickstarter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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