Page Blocks

Hosting sponsored by:

Point In Space

 

API: Str

Filename:
fwpStr_markWebLinks.ctag

Released With:
5.2.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_markWebLinks (Tag)

Description

Takes a body of text, and array of web link definitions and marks up the text replacing phrases with links.

Syntax

fwpStr_markWebLinks: -inText=string, -withLinks=linksPairs;

Parameters & Member Tags

-inText = (required) : a string or bytes of text

-withLinks = (required) : an array of pairs in the format of phrase=link where phrase is the text expected to be found in -inText and link is the URL to link to.

Examples

fwpStr_markWebLinks: 
   -inText='Look at our products page for more ideas.', 
   -withLinks=(array:'products page'='/products/index.html');

This would change Look at our products page for more ideas. to become Look at our <a href="/products.index.html">products page</a> for more ideas.

Source Code

View in separate window

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

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

    {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=            Takes a body of text and an array of pairs, and searches
                    the text for keywords supplied by the pairs and converts
                    them into links. The pairs are in the format of 
                    keyword = linkURL. }

    {maintvsrn=        1.0 }
    {maintrelease=    5.2.0 }
    {maintdate=        2007-06-09 }
    {maintauthor=    Greg Willits }
    {maintnotes=    initial release }

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

define_tag:'fwpStr_markWebLinks',  -priority='replace',
    -required = 'inText',
    -required = 'withLinks', -type = 'array';

    local:'thisLink' = pair;

    iterate: #hrefLinks, #thisLink;

        #text =(string_replaceRegExp:
            #text,
            -find='\\b(' + (#thisLink->first) + ')\\b',
            -replace='<a href="' + (#thisLink->second) + '">\\1</a>',
            -ignoreCase);

    /iterate;

    return: @#text;

/define_tag;
?>

© 2002-2012, pageblocks.org