Page Blocks

Hosting sponsored by:

Point In Space

 

API: Str

Filename:
fwpStr_getSentences.ctag

Released With:
5.0.0

Current Version:
1.0.0

Status: Active

Min Lasso Tested: 8.1.0

Max Lasso Tested: 8.5.3

Related:

Still don't get it?

Check out the talk list archives, or join and ask your questions.

Documentation Error or Request?

Email documentation corrections or comments

API Reference

fwpStr_getSentences (Tag)

Description

Retrieves N sentences (determined by period-space delimiters) from a string. The tag will retrieve sentences across paragraph breaks. The paragraph breaks will be shown by default, but can be suppressed with the -squish option.

Syntax

[fwpStr_getSentences: -str=string, -get=integer, -squish]

Parameters & Member Tags

-str - required : a string

-get - required : the number of sentences to retrieve

-squish - optional : supresses paragraph breaks and runs all sentences together

Examples

[fwpStr_getSentences: -str=(field:'description'), -get='4', -squish]

Source Code

View in separate window

<?lassoscript
//............................................................................
//
//    pageblocks: (c) 2002-2007 http://www.pageblocks.org/
//
//............................................................................
/*

    {fileName=        fwpStr_getSentences.ctag }
    {rsrcType=        tag }
    {rsrcName=        fwpStr_getSentences }
    {rsrcHTTP=        www.pageblocks.org/refc/fwpStr_getSentences }

    {lassoVrsnMin=    8.1.0 }
    {lassoVrsnMax=    8.5.3 }

    {author=        Greg Willits }
    {authorEmail=    subscribe to pbTalk at www.pageblocks.org/talk/ }
    {authorHTTP=    www.pageblocks.org }

    {desc=            This tag returns 'max' chars of string 'str' with an
                    intelligent cutoff at whole words. }

    {maintvsrn=        1.0 }
    {maintrelease=    5.0.0 }
    {maintdate=        2006-01-16 }
    {maintauthor=    Greg Willits }
    {maintnotes=    initial release - replaces fwpUtil_subWords }

*/
//.............................................................................

define_tag:'fwpStr_getSentences', -priority='replace',
    -required='str',
    -required='get';

    local:
        'fw_get'         = #get,
        'fw_allPieces'    = #str->split:'. ',
        'fw_rtnPieces'    = (array);

    if: #fw_get > #fw_allPieces->size;
        #fw_get = #fw_allPieces->size;
    /if;

    loop: #fw_get;
        #fw_rtnPieces->(insert: #fw_allPieces->(get:loop_count));
        #fw_rtnPieces->(insert:'. ');
    /loop;

    #fw_rtnPieces = #fw_rtnPieces->join;
    #fw_rtnPieces->(removetrailing:' ');

    if: params->(find:'-squish')->size > 0;
        #fw_rtnPieces = (local:'fw_rtnPieces', -encodebreak);

        //    html or xhtml?

        if: #fw_rtnPieces >> '<br />';
            #fw_rtnPieces->(replace:'<br /><br />', ' ');
        else;
            #fw_rtnPieces->(replace:'<br><br>', ' ');
        /if;
    /if;

    return: #fw_rtnPieces;

/define_tag;
?>


© 2002-2010, pageblocks.org