TYPO3 - 通过排版和数据库输出图像路径



在我的数据库中是TYPO3媒体图像文件:header_image = 1

表:tx_test

字段:header_image

如何输出图像链接?我想我需要IMG_RESOURCE和记录?

但我现在不起作用。我的测试:

10 = FILES
10 {
    references {
        table = tx_test
        #uid.data = uid
        fieldName = header_image
    }
    renderObj = RECORDS
    renderObj {
        10 = IMG_RESOURCE
        10 {
            file {
                treatIdAsReference = 1
                import.data = file:current:publicUrl
            }
        }
    }
}

效果完美!

#Title
    testTitle = COA
    testTitle {
        # Titel
        10 = RECORDS
        10 {
            source = 1
            dontCheckPid = 1
            tables = tx_test
            conf {
                tx_test = TEXT
                tx_test {
                    field = title
                    crop = 80 | | 1
                    stripHtml = 1
                    htmlSpecialChars = 1
                }
            }
        }
        stdWrap.noTrimWrap = |<title>|</title>|
        stdWrap.insertData = 1
    }

谢谢!

如果你真的只是想要图像的URI,这应该可以完成这项工作。

10 = FILES
10 {
    references {
        table = tx_test
        # YOU NEED AN UID HERE!
        #uid.data = uid
        fieldName = header_image
    }
    renderObj = TEXT
    renderObj {
        data = file:current:publicUrl
    }
}

这里是解决方案:

感谢保罗·贝克

带图像裁剪的图像输出:

10 = FILES
10 {
    references {
        table = tx_ext_name
        uid.data = GP:tx_ext_action|tx_ext_controller
        fieldName = header_image
    }
    renderObj = IMG_RESOURCE
    renderObj {
        file {
            treatIdAsReference = 1
            import.data = file:current:uid
            width = 1200c
            height = 630c
        }
    }
}

或者对于普通图像网址:

10 = FILES
10 {
    references {
        table = tx_ext_name
        uid.data = GP:tx_ext_action|tx_ext_controller
        fieldName = header_image
    }
    renderObj = TEXT
    renderObj {
        data = file:current:publicUrl
    }
}

在阅读了另一个关于 FILES 元素中 uid 的答案的评论中的讨论后,我尝试了一些可能性,如果 TypoScript 嵌入到该记录中用于整个记录,则此方法有效,该记录由 TypoScript 元素CONTENTRECORDS检索。它从保存它的内容元素(这里:tt_content)获取 uid。

10 = FILES
10 {
    references {
        table = tt_content
        uid.field = uid
        fieldName = image
    }
    renderObj = TEXT
    renderObj {
        data = file:current:publicUrl
    }
}

所以整个 TypoScript 可能看起来像这样:

myContent = CONTENT
myContent {
    table = tt_content
    select {
        where = AND {#CType}="tx_mysitepackage_pi1"
        orderBy = sorting desc
    }
    renderObj = COA
    renderObj {
        10 = FILES
        10 {
            references {
                table = tt_content
                uid.field = uid
                fieldName = image
            }
            renderObj = TEXT
            renderObj {
                data = file:current:publicUrl
            }
        }
        20 = TEXT
        20.stdWrap {
            field = header
            noTrimWrap =  |<h1> | </h1>|
        }
    }
}

相关内容

  • 没有找到相关文章

最新更新