2014-10-10 53 views
0

特定的查询我的问题可能看起来微不足道,如果是的话很遗憾!我目前正在学习typo3和typoscript。我想创建一个具有动态背景图像的模板。该图像存储在一个目录中。我想从表tt_content中获取图像名称。然而,这种工作方式让我感到困惑,我不知道我的承诺是否正确。是否有可能写在typoscript

的代码看起来是这样的:

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> 
} 

我想存储有关图像中的可变信息(代码中的股利部分),并把它放到我的模板。我的代码模板部分看起来是这样的:

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

<f:cObject typoscriptObjectPath="headerimage" /> 

所以我的问题是,也是我选择从数据库的东西和存储到一个变量正确的,是路我在模板中调用它们的方式是否正确?如果上面的方式应该工作,但我有一些小错误,是好的做法还是我应该做不同的事情?

亲切的问候

阿迪

回答

1

您的片段将无法正常工作,因为你的结构是非常错误的。

20.headerImagePath = COA 

您尝试在CONTENT OBJECT创建一个新的CONTENT OBJECT ARRAY

20 = CONTENT 

这是行不通的。

但CONTENT对象有一个名为renderObj的属性。

请看下面的例子:

UNTESTED

试试这样说:

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 
        } 


       } 

      } 

     } 

    } 

} 

也看看这个例子:

在这里,他们直接从媒体获得标题图片页面属性中的元素:

http://wiki.typo3.org/TypoScript_Header_Image

+0

您好,感谢信息。我刚刚在阅读本文时找到了解决方案,但是,您的答案非常重要!我不知道COA真的代表了什么(现在写道,我的建设是无稽之谈是有道理的)。 – Adi 2014-10-14 09:31:11

0

获得头形象,也backgound我们,其工作在多语言工作,错字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; 
    } 
    ) 
} 
} 

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