[TYPO3] Random content with limited text

Peter Klein peter at umloud.dk
Wed Mar 5 09:46:53 CET 2008


Hi Eric.
Sorry. for the late reply. but I have been busy with work..

I would reccomend that you read TSRef and look at the css_styled_content 
using the Template Analyzer or TS Object Browser.
Then you can see how things is generated.
http://typo3.org/documentation/document-library/references/doc_core_tsref/4.1.0/view/toc/0/

But here's a complete snippet you can use.

-- Constants Start --
# ID of the page where your content elements are stored
lib.randomContent.pidInList = 74

# Maximum number of content elements to show
lib.randomContent.max = 1

# Maximum number of pixels (width) a block of images inserted as content is 
allowed to consume.
lib.randomContent.maxImageWidth = 200

# Same as above, but this is the maximum width when text is wrapped around 
an imageblock. Default is 50% of the normal Max Image Width
lib.randomContent.maxImageWidthInText = 100

lib.randomContent.morelink.label = Read more

# Maximum length of cropped text
lib.randomContent.cropLength = 150
-- Constants End --

-- Setup Start --
lib.randomContent = COA_INT
lib.randomContent {

  10 = CONTENT
  10 {
    table = tt_content
    select {
      where = CType='textpic'
      # ID of the page where your content elements are stored
      pidInList = {$lib.randomContent.pidInList}
      # Number of content elements to show
      max = {$lib.randomContent.max}
      orderBy = rand()
    }
    renderObj = COA
    renderObj {
      # Here we create a link to the original content element,
      # and store it in a register value. (morelink)
      5 = LOAD_REGISTER
      5.morelink = {$lib.randomContent.morelink.label}
      5.morelink.typolink.parameter.field = pid
      5.morelink.typolink.section.field = uid
      5.morelink.typolink.useCacheHash = 1

      # Use the two new constants "lib.randomContent.maxImageWidth"
      # and "lib.randomContent.maxImageWidthInText" to control the
      # size of the images.
      5.maxImageWidth = {$lib.randomContent.maxImageWidth}
      5.maxImageWidthInText = {$lib.randomContent.maxImageWidthInText}

      # The following code is identical to the "tt_content.textpic"
      # object from css_styled_content
      10 = COA
      10.if.value = 25
      10.if.isLessThan.field = imageorient
      10.10 = < lib.stdheader

      20  < tt_content.image.20

      20.text.10 = COA
      20.text.10 {
        if.value = 24
        if.isGreaterThan.field = imageorient
        10 = < lib.stdheader
        10.stdWrap.dataWrap = <div class="csc-textpicHeader 
csc-textpicHeader-{field:imageorient}">|</div>
      }

      20.text.20 < tt_content.text.20

      # Here we modify the code, so that a version of the bodytext without
      # HTML tags, is shown in a cropped version with a link to the original
      # content element.
      20.text.20.stripHtml = 1
      20.text.20.crop = {$lib.randomContent.cropLength} | ... 
[{register:morelink}] | 1
      20.text.20.insertData = 1

      30 = RESTORE_REGISTER
    }
  }
}
-- Setup End --

-- 
Peter Klein/Umloud Untd


"Eric Thelander" <3d-telis at home.se> skrev i en meddelelse 
news:mailman.3996.1204230201.5943.typo3-english at lists.netfielders.de...
> Hello Peter
>
> Thanks for your help. I used your setup and managed to get the text right, 
> cropped and all. But I need the script to also include the image. Another 
> thing I would like is to place a link "Read more" after the "..."
>
> Best regards
> Eric
>




More information about the TYPO3-english mailing list