Spec-Zone.ru › ColdFusion

cfoutput

Displays output that can contain the results of processing CFML variables and functions. You can use the query attribute to loop over the result set of a database query.

<cfoutput>

writeOutput()

  • CF
  • Lucee
  • BL 1.0.0+
  • See Also: cfloop writeOutput encodeForHTML encodeForHTMLAttribute

    Attribute Reference

    query query

    Name of cfquery from which to draw data for output section.

    group string

    Query column to use to group sets of records. Eliminates adjacent duplicate rows when data is sorted. Use if you retrieved a record set ordered on one or more a query columns. For example, if a record set is ordered on "Customer_ID" in the cfquery tag, you can group the output on "Customer_ID."

    groupcasesensitive boolean

    Whether to consider the case in grouping rows.
    Values:
    • true
    • false

    startrow numeric

    Row from which to start output. Only considered when the query attribute is set.This attribute in combination with maxrows can be used to create some paging.

    maxrows numeric

    Maximum number of rows to display. Only considered when the query attribute is set.

    encodefor string

    CF 2016+ Lucee 5.1+ When set applies an encoder to all variables to prevent XSS. For example if you specify html each variable will be wrapped by a call to the encodeForHTML function.
    Values:
    • html
    • htmlattribute
    • javascript
    • css
    • xml
    • xmlattribute
    • url
    • xpath
    • ldap
    • dn

    Compatibility

    BoxLang:

    Version 1.0.0+ <bx:output> in BoxLang

    Examples
    Sample code using the cfoutput tag

    Simple Tag Example

    <cfoutput>Some text and a #encodeForHTML(variable)#</cfoutput>

    Loop over a query

    Loops over each row of the query specified and outputs the result.

    <cfoutput query="news">
        <h2>#encodeForHTML(news.headline)#</h2>
        <p>#encodeForHTML(news.byline)#</p>
    </cfoutput>

    Loop over a range of rows of a query

    Loops over 10 rows of the query specified starting from row 5 and outputs the result.

    <cfoutput query="news" startrow="5" maxrows="10">
        <h2>#encodeForHTML(news.headline)#</h2>
        <p>#encodeForHTML(news.byline)#</p>
    </cfoutput>

    Using the encodeFor attribute

    CF 2016+ Lucee 5.1+ By specifying encodefor="html" each variable is encoded using the encodeForHTML function before it is output.

    <cfoutput query="news" encodefor="html">
        <h2>#news.headline#</h2>
        <p>#news.byline#</p>
    </cfoutput>

    Using the group attribute

    Creates a dummy query food, with columns name and type. Then outputs the food by grouping by the type.

    <cfset food = queryNew("name,type",
        "varchar,varchar",
        [ {name:"Apple",type:"Fruit"}, 
          {name:"Orange",type:"Fruit"}, 
          {name:"Chicken",type:"Meat"} ])>
    <cfoutput query="food" group="type">
        <h2>#type#</h2>
        <ul>
          <cfoutput><li>#name#</li></cfoutput>
        </ul>
    </cfoutput>

    © 2012–present Foundeo, Inc. and the CFDocs contributors.
    Licensed under the MIT License.
    ColdFusion is a trademark of Adobe Systems Incorporated.
    https://cfdocs.org/cfoutput

    Spec-Zone.ru

    Настройки Оффлайн Что нового Помощь О нас
    Spec-Zone .ru
    спецификации, руководства, описания, API