2012-02-21 4 views
4

Typo3 4.5.3을 사용하고 있고 임의로 현재 페이지에 표시 할 디렉토리를 선택하는 디렉토리에 이미지 파일이 있지만 listmark = rand 작업을하기 위해 타이프 스크립트를 가져올 수 없습니다. . 내 확장 템플릿은 다음과 같습니다.typoscript를 사용하여 디렉토리의 파일에서 임의의 이미지를 선택하는 방법은 무엇입니까?

# Pick a random image to display 
temp.banner = IMAGE 
temp.banner { 
    file { 
    height = 165 
    width = 954 
    import { 
     filelist = {$templatePathPrefix}images/banners | jpg,jpeg,png,gif | name | | 1 
     listNum = rand 
    } 
    } 
    params = class="bannerPic" 
} 

listnum 설정을 0, 1 등으로 변경하면 해당 img HTML이 페이지에 삽입됩니다. 'last'로 설정하면 작동하지만, 항상은 새로 고침 한 횟수에 관계없이 첫 번째 이미지를 삽입합니다. 특정 이미지 (0, 1, ...)를 선택할 수 있으므로 일반 설정이 작동한다는 것을 알고 있으며, 무작위 선택이 아닙니다.

나는 COA_INT 개체에서 외부 개체를 래핑하는 rand의 다양한 용도에 대해 TS를 보았지만 나에게도 해당되지 않았습니다. listNum = rand를 배치 할 위치에 대해 뭔가를 놓쳤습니까? 나는 Typo3에서 꽤 새롭다. 그래서이 시점에서 아직도 많이 불투명하다. 제공 할 수있는 통찰력에 감사드립니다.

답변

2

mak_stdwrapextended extension은 listNum과 함께 rand를 사용할 수있는 가능성을 추가합니다.

4.5에서 잘 작동합니다.

1

TypoScript를 통해 무작위로 선택하는 것을 권장하지 않습니다. 페이지를로드 할 때마다 임의의 이미지를 원하기 때문에 무작위 요소는 USER_INT 또는 COA_INT 요소 여야하므로 캐시 할 수 없습니다.

간단한 해결책은 JavaScript를 통해이를 수행하는 것입니다. 클라이언트에서 JavaScript를 사용할 수없는 경우 기본 이미지를 정의하고 임의로 이미지를 선택하는 JavaScript를 정의합니다. 이 솔루션을 사용하면 매번 무작위 이미지를 얻을 수 있으며 콘텐츠는 완벽하게 캐시 할 수 있습니다.

다음 TypoScript 코드는 이러한 사실에 영감을 줄 수 있습니다. 기본적으로 border column에서 Image-Elements를 읽어와 임의로 출력하기 위해 JavaScript를 생성합니다. 또한 이미지는 링크 가능합니다.

lib.teaser = COA 
lib.teaser.10 = CONTENT 
lib.teaser.10 < styles.content.getBorder 
lib.teaser.10 { 
    slide = -1 
    table=tt_content 
    select{ 
     begin = 0 
     max = 1 
     #language 
     languageField=sys_language_uid 
     #from wich column 
     where=colPos=3 
    } 
    wrap=<div class="teaserimage">|</div> 

    renderObj=COA 

    #image with gallery function 
    renderObj.10 = COA 
    renderObj.10 { 
     stdWrap.required=1 
     # get image 
     10 = IMAGE 
     10 { 
      #if not empty 
      required=1 
      file.import=uploads/pics/ 
      file.import.field=image 
      #file.width=266 
      #file.height=180 
      file.import.listNum = 0 
      stdWrap.insertData=1 
      params = id="imgbig_{TSFE:currentRecord}" 
      imageLinkWrap < tt_content.image.20.1.imageLinkWrap 
      imageLinkWrap.typolink.ATagParams = id="link_imgbig_{TSFE:currentRecord}" 
      imageLinkWrap.typolink.ATagParams.stdWrap.insertData=1 
     } 

     # standard image configuration from tt_content 
     10.altText < tt_content.image.20.1.altText 
     10.titleText < tt_content.image.20.1.titleText 
     10.longdescURL < tt_content.image.20.1.longdescURL 

     # random function for gallery images 
     30 = COA 
     30 { 
      stdWrap.required=1 
      stdWrap.dataWrap(
      <script type="text/javascript"> 
      /* <![CDATA[ */ 
      var imgArray = new Array(|); 
      var randnum = Math.round(Math.random()*(imgArray.length-1)); 
      document.getElementById('imgbig_{TSFE:currentRecord}').src ='uploads/pics/' + imgArray[randnum]; 
      /* ]]> */ 
      </script> 
      ) 

      # first gallery image 
      10 = TEXT 
      10.field = image 
      10.listNum.splitChar=, 
      10.listNum=0 
      10.if.isTrue.field=image 
      10.if.isTrue.listNum=1 
      10.if.isTrue.listNum.splitChar=, 
      10.dataWrap = "|" 


      # other gallery images 
      20 = TEXT 
      20.field = image 
      20.split { 
       token = , 
       cObjNum = 1 
       1 = COA 
       1.if.isPositive.data = TSFE:register|SPLIT_COUNT 
       1 { 
        10 = TEXT 
        10.data = current:1 
        10.dataWrap = ,"|" 
       } 
      } 
     } 
     # random function for gallery links 
     40 = COA 
     40 { 
      stdWrap.required=1 
      stdWrap.dataWrap(
      <script type="text/javascript"> 
      /* <![CDATA[ */ 
      //var imgLinkArray = new Array(randnum); 
      var imgLinkArray = new Array(|); 
      if(document.getElementById('link_imgbig_{TSFE:currentRecord}')) document.getElementById('link_imgbig_{TSFE:currentRecord}').href = imgLinkArray[randnum]; 
      /* ]]> */ 
      </script> 
      ) 

      # first gallery link    
      10 = TEXT 
      10.field = image_link 
      10.listNum.splitChar=, 
      10.listNum=0 
      10.dataWrap = "|" 
      10.typolink.parameter.field = image_link 
      10.typolink.returnLast = url 

      # other gallery links 
      20 = TEXT 
      20.field = image_link 
      20.split { 
       token = , 
       cObjNum = 1 
       1 = COA 
       1.if.isPositive.data = TSFE:register|SPLIT_COUNT 
       1 { 
        10 = TEXT 
        10.data = current:1 
        10.dataWrap = ,"|" 
        10.typolink.parameter.data = current:1 
        10.typolink.returnLast = url 
       } 
      } 
     } 
    } 
} 
1

만 TYPO3 V4.6 코어에 LISTNUM = 랜드를 가지고 위 /를 class.tslib_content.php 당신이 tslib를 확장해야 TYPO3의 V4.5이 http://forge.typo3.org/issues/16180

참조

$TYPO3_CONF_VARS['FE']['XCLASS']['tslib/class.tslib_content.php'] = PATH_site.'fileadmin/template/class.ux_tslib_content.php'; 

을하고 class.ux_tslib_content.php이 코드를 추가합니다 :이 localconf.php에 추가

<?php 
/*************************************************************** 
* Copyright notice 
* 
* (c) 1999-2008 Kasper Skaarhoj ([email protected]) 
* All rights reserved 
* 
* This script is part of the TYPO3 project. The TYPO3 project is 
* free software; you can redistribute it and/or modify 
* it under the terms of the GNU General Public License as published by 
* the Free Software Foundation; either version 2 of the License, or 
* (at your option) any later version. 
* 
* The GNU General Public License can be found at 
* http://www.gnu.org/copyleft/gpl.html. 
* A copy is found in the textfile GPL.txt and important notices to the license 
* from the author is found in LICENSE.txt distributed with these scripts. 
* 
* 
* This script is distributed in the hope that it will be useful, 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
* GNU General Public License for more details. 
* 
* This copyright notice MUST APPEAR in all copies of the script! 
***************************************************************/ 
/** 
* Contains classes for Content Rendering based on TypoScript Template configuration 
* 
* $Id: class.tslib_content.php 4254 2008-09-27 13:35:44Z dmitry $ 
* Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj 
* XHTML compliant 
* 
* class tslib_cObj   :  All main TypoScript features, rendering of content objects (cObjects). This class is the backbone of TypoScript Template rendering. 
* 
* @author Kasper Skaarhoj <[email protected]> 
*/ 

/** 
* This class contains all main TypoScript features. 
* This includes the rendering of TypoScript content objects (cObjects). 
* Is the backbone of TypoScript Template rendering. 
* 
* There are lots of functions you can use from your include-scripts. 
* The class "tslib_cObj" is normally instantiated and referred to as "cObj". 
* When you call your own PHP-code typically through a USER or USER_INT cObject then it is this class that instantiates the object and calls the main method. Before it does so it will set (if you are using classes) a reference to itself in the internal variable "cObj" of the object. Thus you can access all functions and data from this class by $this->cObj->... from within you classes written to be USER or USER_INT content objects. 
* 
* @author Kasper Skaarhoj <[email protected]> 
* @package TYPO3 
* @subpackage tslib 
* @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&cHash=4ad9d7acb4 
*/ 
class ux_tslib_cObj extends tslib_cObj{ 


    /** 
    * Exploding a string by the $char value (if integer its an ASCII value) and returning index $listNum 
    * 
    * @param string  String to explode 
    * @param string  Index-number. You can place the word "last" in it and it will be substituted with the pointer to the last value. You can use math operators like "+-/*" (passed to calc()) 
    * @param string  Either a string used to explode the content string or an integer value which will then be changed into a character, eg. "10" for a linebreak char. 
    * @return string 
    */ 
    function listNum($content,$listNum,$char) { 
     $char = $char ? $char : ','; 
     if (t3lib_div::testInt($char)) { 
      $char = chr($char); 
     } 
     $temp = explode($char,$content); 
     $last = ''.(count($temp)-1); 
     if($listNum === 'rand'){ $listNum = rand(0,count($temp)-1);} //taywa added: rand feature! 
     $index=$this->calc(str_ireplace('last',$last,$listNum)); 
     return $temp[$index]; 
    } 

} 


?> 
관련 문제