[TYPO3-english] add style="background-image(); " with IMG_RESOURCE + LOAD_REGISTER?

Christopher Torgalson bedlamhotel at gmail.com
Tue Aug 30 18:50:05 CEST 2011


Hi,

On Tue, Aug 30, 2011 at 8:02 AM, Jigal van Hemert <jigal at xs4all.nl> wrote:
> Hi,
>
> On 30-8-2011 15:36, Mark Roemermann wrote:
>>
>> Hi list, I've been banging my head against a wall with this.  Is there a
>> way to create a H1 tag that takes a page title and subtitle, and adds a
>> style attribute that is pulled from the page media?
>>
>> eg:
>>
>> <h1 style="background: url(page:media)
>> no-repeat;>page:title<span>page:subtitle</span></h1>
>
> Not the prettiest solution (I don't like splitting paired HTML tags over two
> properties), but it works:
>
> 10 = TEXT
> 10 {
>  data = page:title
>  innerWrap = |<span>{page:subtitle}</span>
>  innerWrap.insertData = 1
>  preCObject = IMG_RESOURCE
>  preCObject {
>    file {
>      import = uploads/media/
>      import.data = page:media
>      import.listNum = 0
>      height = 200
>      width = 600
>    }
>    stdWrap.wrap = <h1 style="background: url(|) no-repeat;">
>  }
>  postCObject = TEXT
>  postCObject.value = </h1>
> }


This can also be done by rewriting (or copying and rewriting if this
is happening outside regular content elements) lib.stdHeader and using
the registry. The following sample is taken from my
(obsoleted-by-webfonts) extension bh_firtools [1], but it's pretty
much the same in css_styled_content [2]--search for lib.stdheader.

[1] http://typo3.org/extensions/repository/view/bh_firtools/current/info/static%252FNew%2BFIR%2BExtras%252Fsetup.txt
[2] http://git.typo3.org/TYPO3v4/Core.git?a=blob;f=typo3/sysext/css_styled_content/static/v4.5/setup.txt;h=74a1e17e50e350b50d116e420d547568ca8956b7;hb=a6e3aea63d50481056a7d79cda3754277b805fdf

### Modify lib.stdheader to output a class and an id attribute on every h1:
###
lib.stdheader.stdWrap.dataWrap >
lib.stdheader {
    2 {
        headerStyle.noTrimWrap = | style="text-align:|"|
    }

    3 {
        ### Because we're always going to use .fir for
lib.stdheader.10.1 (as opposed to
        ### h1 elements that might be inserted by the RTE), we've move
the class attribute
        ### into lib.stdheader.10.1.fontTag below. This means that we
need to just wrap
        ### the header class--if it occurs at all--with a leading space:
        ###
        headerClass.noTrimWrap = | ||
    }

    ### But we're not allowing TYPO3 to set other classes in h1
elements in this case!
    ###
    3 >

    ### Load a register with the current h1 element's uid:
    ###
    4 = LOAD_REGISTER
    4 {
        BH_FIR_headerUid {
            field = uid
            required = 1
        }
    }

    ### Build the h1 element:
    ###
    10 {
        ### Unset the default CSS_STYLED_CONTENT stuff:
        ###
        1 >
        1 = COA
        1 {
            ### Wrap the current value (.5) with the desired markup.
This will output h1 elements looking
            ### something like this:
            ###
            ###    <h1 id="h1_123" class="fir">Lorem ipsum dolor sit amet</h1>
            ###
            stdWrap.dataWrap = <h1 id="h1_{register:BH_FIR_headerUid}"
class="fir{register:headerClass}">|</h1>
            5 = HTML
            5 {
                value {
                    current = 1
                }
            }
            fontTag >
        }

        2 {
           stdWrap >
        }

        3 {
            stdWrap >
        }

        4 {
            stdWrap >
        }

        5 {
            stdWrap >
        }

        6 {
            stdWrap >
        }
    }
}

-- 
Christopher Torgalson
http://www.typo3apprentice.com/


More information about the TYPO3-english mailing list