You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TYPO3技术问询:如何仅获取记录的部分内容?

How to Output Only Specific Fields from a Mask Content Element (e.g., Teaser Text)

Absolutely! You totally can pull just specific parts (like only the text field) from your Mask-created content element for teasers or reuse elsewhere in your TYPO3 site. Here are a few practical ways to make this happen:

1. Create a Custom Teaser Template in Mask

Mask lets you define multiple template variants for the same content element—perfect for full-content vs. teaser use cases. Here's how:

  • Head to the Mask module in your TYPO3 backend, find your content element, and click "Edit".
  • Navigate to the Templates section, then add a new template (name it something like Teaser).
  • In this new template, strip out everything except the code that renders your text field. For example:
    <div class="content-teaser">
        {data.tx_mask_mytextfield -> f:format.html()}
    </div>
    
    Replace tx_mask_mytextfield with the actual database column name of your text field (you can find this in Mask's field list for the element).
  • Save the template. Now, when you add this content element to a page, you can select the "Teaser" template from the dropdown to only render the text.

2. Directly Render Specific Fields in Fluid

If you don't want to create a separate Mask template, you can call the field directly from any Fluid template (like a page layout or teaser container):

  • First, make sure you have access to the content element record in your template (e.g., via a TYPO3 query or a variable passed into the template). Let's say the record is stored in {teaserElement}.
  • Output just the text field like this:
    <div class="teaser-item">
        {teaserElement.tx_mask_mytextfield -> f:format.html()}
    </div>
    
    • Use f:format.html() if your text is from a rich text editor (RTE) to preserve basic formatting; skip it if it's plain text.

3. Use TypoScript to Fetch & Render the Field

For more control (like reusing the teaser across multiple pages), you can define a TypoScript object to pull the field:

lib.contentTeaser = CONTENT
lib.contentTeaser {
    table = tt_content
    select {
        uidInList = 456  # Replace with your content element's UID
        where = CType = 'mask_myelementkey'  # Replace with your Mask element's CType
    }
    renderObj = TEXT
    renderObj {
        field = tx_mask_mytextfield
        parseFunc < lib.parseFunc_RTE  # Keep this for RTE-formatted text
    }
}

Then call this object in your Fluid template:

<f:cObject typoscriptObjectPath="lib.contentTeaser" />

Quick Tips

  • Double-check the field name and CType—Mask prefixes fields with tx_mask_ and uses mask_ + your element's key as the CType.
  • If you're pulling content from another page, ensure your select query includes the correct storage folder or page ID.
  • For multiple teaser items, use a Fluid <f:for> loop to iterate over a collection of content elements and render each text field individually.

内容的提问来源于stack exchange,提问作者Michael

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 09:10:35