简体   繁体   English

TYPO3 DCE:部分图像

[英]TYPO3 DCE: image in section

How can I use a image field in a DCE section?如何在 DCE 部分使用图像字段?

An image element (myImage) can be accessed like this:可以像这样访问图像元素(myImage):

<f:for each="{dce:fal(field:'myImage', contentObject:contentObject)}" as="fileReference">
   <f:image src="{fileReference.uid}" alt="" treatIdAsReference="1" />
</f:for>

But if I loop through a section (mySection), this code does not work.但是,如果我遍历一个部分(mySection),则此代码不起作用。

Solution after lots of debug:经过大量调试后的解决方案:

  1. Use this element for "myImage": File Abstraction Layer (section use only)将此元素用于“myImage”:文件抽象层(仅部分使用)

     <config> <type>group</type> <internal_type>db</internal_type> <appearance> <elementBrowserType>file</elementBrowserType> <elementBrowserAllowed>jpg,jpeg,png,gif</elementBrowserAllowed> </appearance> <allowed>sys_file</allowed> <size>1</size> <minitems>1</minitems> <maxitems>1</maxitems> <show_thumbs>1</show_thumbs> </config>
  2. Use this template code使用此模板代码

     <f:for each="{field.mySection}" as="teaserbox"> <f:image src="{teaserbox.image}" alt="" /> {teaserbox.text} </f:for>

You have to remove treatIdAsReference="1" - it will cause this error:您必须删除treatIdAsReference="1" - 它会导致此错误:

    No file usage (sys_file_reference) found for given UID.

This is not the 100% perfect solution, as you don't have the fields like alt , but it works.这不是 100% 完美的解决方案,因为您没有像alt这样的字段,但它有效。 Better solutions are welcome!欢迎更好的解决方案!

This was not possible in older DCE versions.这在较旧的 DCE 版本中是不可能的。 In the newer ones you can choose FAL Image for Section Configuration.在较新的版本中,您可以为 Section Configuration 选择 FAL Image。 That looks like this:看起来像这样:

<config>
<type>group</type>
<internal_type>db</internal_type>
<appearance>
    <elementBrowserType>file</elementBrowserType>
    <elementBrowserAllowed>jpg,jpeg,png,gif</elementBrowserAllowed>
</appearance>
<allowed>sys_file</allowed>
<size>5</size>
<minitems>0</minitems>
<maxitems>5</maxitems>
<show_thumbs>1</show_thumbs>
</config>

And in your template this should work:在您的模板中,这应该有效:

<f:for each="{item.image -> dce:explode()}" as="imageUid">
    <f:image src="file:{imageUid}"/>                        
</f:for>
//this is file upload control with little changes 

<config>
<type>group</type>
<internal_type>db</internal_type>
<appearance>
    <elementBrowserType>file</elementBrowserType>
    <elementBrowserAllowed>jpg,jpeg,png,gif</elementBrowserAllowed>
</appearance>
<allowed>sys_file</allowed>
<size>5</size>
<minitems>0</minitems>
<maxitems>5</maxitems>
<show_thumbs>1</show_thumbs>

<dce_load_schema>1</dce_load_schema>
<dce_get_fal_objects>1</dce_get_fal_objects>

It will look like In Dce backend it will look like below image它看起来像在 Dce 后端它看起来像下图

In my case it will look like this在我的情况下,它看起来像这样

<f:for each="{field.contentBoxes}" as="contentbox">
    <div class="col-lg-4 col-md-4 col-sm-6">
        <div class="choose__item">
            <f:for each="{contentbox.icon}" as="image">
                <f:image image="{image}"  />
            </f:for>
            <f:format.html>{contentbox.content}</f:format.html>
        </div>
     </div>
 </f:for>    

Now In your case you should try like this现在在你的情况下,你应该像这样尝试

<f:for each="{field.mySection}" as="teaserbox">
   <f:for each="{teaserbox.image}" as="img">
      <f:image image="{img}"  />
   </f:for> 
   {teaserbox.text}
</f:for>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM