2016-12-05 102 views
1

我需要一个typoscript来为每个菜单条目添加缩略图,方法是从页面属性获取图片NOT,但是从指定列的第一个内容元素获取图片NOT。TYPO3 - 从子页面CONTENT中获取menue的缩略图

当前菜单的输入框是:它基本上生成一个名为“新闻”的子页面列表。

temp.newsPage = COA 
temp.newsPage.40 = HMENU 
temp.newsPage.40 { 
    special = directory 
    special.value = {$plugin.tx_rstwstdtpl.settings.menuNewsPagesStart} 
    includeNotInMenu = 1 
    wrap = <div class="news-latest-container">|</div> 
    1 = TMENU 
    ### sortieren nach DATUM ### 
    1.alternativeSortingField = lastUpdated DESC 
    ### sortierung ende ### 
    1.NO.allWrap.insertData = 1 
    1.NO.allWrap = <div class="news-latest-item">|</div> 
    1.NO.doNotLinkIt = 1 
    1.NO.doNotShowLink = 1 
    1.NO.before.cObject = COA 
    1.NO.before.cObject { 
    5 = COA 
    5.10 = TEXT 
    5.10.value = <div class="selector date 
    # DATUM 
    5.30 = TEXT 
    5.30.field = lastUpdated 
    5.30.strftime=%Y 
    5.90 = TEXT 
    5.90.value = "> 
# letzte Aenderung 
    10 = TEXT 
    # anzeige NewsDATUM = metadaten - lastupdated 
    10.field = lastUpdated 
    # 10.strftime=%d.%m.%Y %H:%M 
    10.strftime=%d.%m.%Y 
    10.wrap = <span class="news-latest-date">|</span><br /> 
# title 
    20 = TEXT 
    20.field = title 
    20.wrap = <h2><span class="news-latest-header">|</span></h2> 
    20.typolink.parameter.field = uid 
# text 
    30 = TEXT 
    30.field = abstract 
    30.crop = {$plugin.tx_rstwstdtpl.settings.teaserTextLength}|&nbsp;...|1 
    30.wrap = <p>|</p> 
    30.required = 1 

    40 = TEXT 
    40.value = </div> 
    } 
} 

很容易从子页面的页面属性/媒体生成缩略图。但不知道typoscript-query如何适用于子页面的内容。

非常感谢你, 托马斯

回答

0

你需要的是一个一个选择收集的属于在你的页面当前生成传情特列tt_content记录的UID。
可以使用对象RECORDS或CONTENT在typoscript中完成。

例如使用before.cObject 35这样的:

35 = CONTENT 
35 { 
    table = tt_content 
    select { 
    // we are in context of that page, so data is the pages record 
    pidInList.field = uid 
    // the special column: 
    where = colPos = 123 
    // select only content with images (something like:) 
    andWhere = media > 0 
    // one image is enough 
    max = 1 
    } 
    // now we have to do it a little more complicated as images are 
    // handled with FAL records 
    renderObj = FILES 
    renderObj { 
    references { 
     table = tt_content 
     // we are now in context tt_content 
     uid.data = current:originalUid // current:uid 
     // depending whether you use CSC or FSC: 
     fieldName = media 
    } 
    renderObj = IMAGE 
    renderObj { 
     file { 
     import.data = file:current:uid 
     treatIdAsReference = 1 
     width = 150c 
     height = 150c 
     } 
     altText.data = file:current:alternative 
     titleText.data = file:current:title 
     params = class="menu-img" 
     stdWrap.typolink.parameter.field = pid 
    } 
    maxItems = 1 
    } 

我希望这是正确的,因为我收集它无需验资。

和顺便说一句:利用包装(例如用dataWrap你甚至可以插入数据)而不是非常大的COA,所以你可以确定匹配开放和结束标签。

0

这是另一个可以用作资源的类似方法的代码片段。这原本是一个带有逗号的子页面列表,但它可以很容易地成为常规菜单。

我在renderObj中使用了fluidtemplates,但是你也可以使用普通的TypoScript。

# TEASER NAV 
##################################################################### 

lib.subpages_teaser = HMENU 
lib.subpages_teaser { 
    // I use a directory menu here 
    special = directory 
    // but this could also be a normal menu without "special" property 
    // directory menu entrypoint 
    special.value = 123 
    // alternatively: entrypoint for use as teasers of subpages 
    // special.value.data = leveluid:-1 

    // exclude shortcut 
    excludeDoktypes = 4 
    // but show "not in menu" pages (if needed) 
    //includeNotInMenu = 1 
    1 = TMENU 
    1 { 
    NO { 
     // * If you want to link only certain parts of the following COA: 
     // doNotLinkIt = 1 
     allWrap = <section>|</section> 
     stdWrap.cObject = COA 
     stdWrap.cObject { 
     10 = COA 
     10 { 
      // * If doNotLinkIt is enabled, link this part 
      // stdWrap.typolink.parameter.data = field:uid 
      // get data from Content Element 
      10 < styles.content.get 
      10 { 
      select { 
       // https://forum.typo3.org/index.php/t/192687/content-in-tmenu 
       selectFields = image 
       pidInList.data = field:uid 
       where = colPos=13 
      } 
      // and process it via a fluidtemplate 
      renderObj = FLUIDTEMPLATE 
      renderObj { 
       // https://stackoverflow.com/questions/36072136/pass-content-from-typoscript-to-fluid-template-in-typo3-7-6 
       file = path/to/my/partials/TeaserImage.html 
       dataProcessing { 
       10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor 
       10.references.fieldName = image 
       } 
      } 
      } 
      20 = TEXT 
      20 { 
      field = nav_title // title 
      wrap = <h2>|</h2> 
      } 
      // LEAD 
      30 < styles.content.get 
      30 { 
      select { 
       selectFields = header 
       pidInList.data = field:uid 
       where = colPos=2 
      } 
      renderObj = FLUIDTEMPLATE 
      renderObj { 
       file = path/to/my/partials/TeaserLead.html 
      } 
      } 
     } 
     } 
    } 
    } 
} 

下面是为renderObj流体模板之一的例子:

<figure> 
    <f:if condition="{files.0}"> 
    <f:then> 
    <img src="<f:uri.image image="{files.0}" width="419" height="279c"/>" 
     alt="{files.0.alternative}" 
     /> 
    </f:then> 
    <f:else> 
     <f:image src="/fileadmin/my/images/grey.png" width="600" height="750c"/> 
    </f:else> 
    </f:if> 
</figure> 

相关链接:

时代的老http://www.typo3wizard.com/de/artikel/das-content-objekt.html帮助我理解内容对象。

https://forum.typo3.org/index.php/t/192687/content-in-tmenu基本上是你的问题,导致select.pidInList.data = field:uid

Pass content from TypoScript to fluid template in TYPO3 7.6是关于如何让图像进入Fluidtemplate。