Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Lorem Ipsum text generator

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sat Jan 16, 2010 9:37 pm    Post subject: Lorem Ipsum text generator Reply with quote

A simple plugin to generate Lorem Ipsum text. Lorem Ipsum is dummy text used for printing and typesetting for centuries, and now you can generate it as filler to see how your templates will look with content. The output will generate a new paragraph every 446 chars (default length.)

Example template:

Code:
{lorem}


Output:

Code:
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>


Possible args
Code:
{lorem length=1000}    // 1000 chars in length
{lorem p_tags=false}   // do not include <p></p> tags


And the plugin source:

Code:
<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.lorem.php
 * Type:     function
 * Name:     lorem
 * Author:   Monte Ohrt
 * Date:     Jan 16th, 2010
 * Purpose:  outputs lorem ipsum text
 * -------------------------------------------------------------
 */
function smarty_function_lorem($params, &$smarty)
{
    $length = isset($params['length']) ? (int)$params['length'] : 446;
    $p_tags = isset($params['p_tags']) ? (bool)$params['p_tags'] : true;

    $repeat = $length <= 446 ? 1 : ceil(($length/446));

    $lorem_text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n";

    $lorem_text =  substr(str_repeat($lorem_text,$repeat),0,$length);

    if($p_tags) {
      $lorem_text =  preg_replace(array('!^!','!\n!','!$!'),array('<p>',"</p>\n<p>","</p>\n"),$lorem_text);
    }

    return $lorem_text;

}
?>
Back to top
View user's profile Send private message Visit poster's website
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Tue Jan 26, 2010 5:59 pm    Post subject: DIV em'all Reply with quote

Smarty Tags that produce full set of HTML can themselves cause design error in the template files. So, I prefer to wrap them with <div> and </div> tags.

My ideal examples would be:

Code:
<div>{lorem}</div>


This preserves the html layout to some extent.

In fact, this plugin helped better, when I did not have the real contents.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jan 26, 2010 6:02 pm    Post subject: Reply with quote

Yep, <p> is just default so they will break like paragraphs, you can change those to <div> if it works better for you.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP