Is it possible to write a specific query in typosc

2019-09-19 06:05发布

my question may seem trivial, sorry if it is! I am currently learning typo3 and typoscript. I want to create a template with a dynamic background image. This image is stored in a directory. I would like to get the image name from the table tt_content. However, the way this works confuses me a bit and i don't know if my take on it is the right one.

The code looks like this:

20 = CONTENT
20.table = tt_content
20.select{
    where = pid = 79
}
20.headerImagePath = COA
20.headerImagePath {
    10 = TEXT
    10.stdWrap.field = image
    10.stdWrap.wrap = <div class="background-media" style="background-image: url('|'); background-repeat: no-repeat; background-size: cover; background-attachment: fixed; background-position: 50%;" data-start="background-position:50% 50%"
                            data-70-top-bottom="background-position:50% 70%">
                      </div>
}

I'd like to store the information about the image (the div part in the code) in a variable and put it into my template. The template part of my code looks like this:

<f:format.raw>{headerimage}</f:format.raw>

or

<f:cObject typoscriptObjectPath="headerimage" />

So my question would be, is the way i am selecting things from the database and storing into a variable correct and is the way i am calling them in the template correct? If the way above should work but i have some little errors, is it good practice or should i do things differently?

Kind Regards

Adi

2条回答
一夜七次
2楼-- · 2019-09-19 06:41

to get header image as backgound us,its working also in multilanguage work with typo 6.x

page.cssInline {
10 = FILES
10 { 
    references.data =  levelmedia:-1, slide
    references.listNum = 0
    renderObj = TEXT
    renderObj.data = file:current:publicUrl
    renderObj.wrap (
     .title-1 {
      background-image: url(../|) !important;  
     }
    ) 
 }  
}

thanks to http://www.derhansen.de/2013/02/using-fal-media-in-typo3-60-for-inline.html

查看更多
▲ chillily
3楼-- · 2019-09-19 06:43

your snippet will not work, because your structure is very wrong.

On

20.headerImagePath = COA

you try to create a new CONTENT OBJECT ARRAY on a CONTENT OBJECT.

20 = CONTENT

This will not work.

But the CONTENT Object has a property called renderObj.

Look at following example:

UNTESTED

Try it like this:

lib.headerImagePath = CONTENT
lib.headerImagePath {

    # first call the content you need
    table = tt_content
    select {

        # Add your colPos
        # In this example i store my header image in colpos 9
        where = colPos = 9

        # PID from current field or define your own
        # pidInList = 123 
        pidInList.field = uid

        languageField = sys_language_uid
    }

    renderObj = COA
    renderObj {

        # FILES object was introduced in TYPO3 6.x
        10 = FILES
        10 {

            # Set a reference to let the file object know, where we will get the images
            references {
                table = tt_content
                uid.field = uid
                fieldName = image
            }

            # make sure we only get the first image in set
            maxItems = 1

            renderObj = COA
            renderObj {

                # We only need the url and not the complete image. So we need a IMG_RESOURCE and not an IMAGE Object
                10 = IMG_RESOURCE
                10 {

                    stdWrap {
                        wrap = <div class="background-media" style="background-image: url('|'); background-repeat: no-repeat; background-size: cover; background-attachment: fixed; background-position: 50%;" data-start="background-position:50% 50%" data-70-top-bottom="background-position:50% 70%"></div>
                        required = 1
                    }

                    # Import file from current object
                    # and treat the id as a reference (TYPO3 File Abstraction Layer)
                    file {
                        import.data = file:current:uid
                        treatIdAsReference = 1
                    }


                }

            }

        }

    }

}

Also look at this examples:

Here they get the header image directly from the MEDIA Element in the page properties:

http://wiki.typo3.org/TypoScript_Header_Image

查看更多
登录 后发表回答