This Rawfield Example

When using the sqlquery macro to display a number of items, and (one of) the fields you want to display contains vipers which should be executed, you would need to use the this.rawfield() viper enclosed within a sxml.execute() viper.

The this.rawfield() viper returns the exact string from the database, whereas the this.field viper will encode the returned string (if it's a string field) to disable both viper and module processing.

Smartsite SXML CopyCode image Copy Code
<se:region error="Invalid request">
    {buffer.set(dt, request.query('m', default='200901'))}
    {buffer.set(dtfrom, datetime.setdate(datetime.now(), string.substring($dt, 0, 4), string.substring($dt, 4, 2), 1))}
    {buffer.set(dtto, sys.iif(request.query.exists(m), datetime.addmonths($dtfrom, 1), datetime.addyears($dtfrom, 100)))}

    <se:sqlquery error="{this.error.message()}">
        <se:parameters>
            <se:parameter name="sql">
                SELECT TOP 10 c.Nr, c.Title, c.Body, c.Author, c.AddDate, c.Code
                FROM {channel.view()} c
                JOIN Contenttypes ct ON c.Contenttype=ct.Nr
                WHERE ct.Code = 'NWS'
                AND (adddate BETWEEN ?:fromdate AND ?:todate)
                ORDER by c.AddDate DESC                
            </se:parameter>        
            <se:parameter name="params">
                <se:collection>
                    <se:member name="fromdate" type="datetime">{buffer.get(dtfrom)}</se:member>
                    <se:member name="todate" type="datetime">{buffer.get(dtto)}</se:member>
                </se:collection>
            </se:parameter>
            <se:parameter name="format">
                <se:rowformat expression="cms.ischildof(this.field(nr),translation.arg(2, default=itemdata.number()))">
                    <div class="news">
                        <div class="newsheader">
                            <div class="newstitle">
                                <a href="{channel.link(this.field(nr))}"><h2><span>{this.field(title)}</span></h2></a>
                            </div>                        
                        </div>
                        <div class="newsbody">
                            <div class="newstext">
                                {sxml.execute(this.rawfield(body))}
                            </div>
                        </div>
                    </div>                
                </se:rowformat>
            </se:parameter>
            <se:parameter name="resultformat">
                {this.result()}
            </se:parameter> 
            <se:parameter name="default">
                        <p>No news items.</p>
            </se:parameter>
        </se:parameters>
    </se:sqlquery>
</se:region>