|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
formfunction Smarty n00b
Joined: 04 Mar 2004 Posts: 3 Location: Cape Town, South Africa
|
Posted: Mon Mar 08, 2004 11:26 am Post subject: modifier.highlight_char.php |
|
|
Hi all,
I noticed alot of people post plugin contributions here, so I thought I'd add one of mine as well, hope thats acceptable in this forum!!
Quite simple, just lets you apply a nice style to the first letter of a string, useful for page titles, or fancy paragraphs, etc.
HTH,
Mark
Summary
This modifier wraps the first character of the input string with a css class using by default a span tag. This is typically used when one wants to alppy a special formatting to things like page headers, etc. The modifier allows you to control what css class if used, and what tag is used. You can also opt to wrap with just an HTML tag and ignore the css class.
Example
Code: |
// where $x = "Hallo world"
Smarty code:
{$x|highlight_char:myFancyStyle}
Output:
<span class="myFancyStyle">H</span>allo world
Smarty code:
{$x|highlight_char:myFancyStyle:div}
Output:
<div class="myFancyStyle">H</div>allo world
Smarty code:
{$x|highlight_char:none:b} {* using "none" as the css class causes modifier to ignore this option}
Output:
<b>H</b>allo world
|
Known Issues
None
Code
Code: |
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {highlight_char} modifier plugin
*
* Type: modifier<br>
* Name: highlight_char<br>
* Date: March 8, 2004<br>
* Purpose: highlight first character of the input string with css class<br>
* Input:
* - string = string whose first char should be wrapped in the given class
*
* Examples:<br>
* <pre>
* {$xxx|highlight_char:big_font}
* Output:
* <span class="bigfont">x</span>xx
*
* {$xxx|highlight_char:none:b} {* you cannot leave a param empty, so none is no class *}
* Output:
* <b>x</b>xx
*
* </pre>
* @author Mark Hewitt <mark at formfunction dot co dot za>
* @version 1.0
* @param string $string Text to modify
* @param string $css_class CSS classname to put in span tags, use 'none' to ignore
* @param string $tag_name (Optional) Tag to wrap first char in
* @param Smarty
* @return string|null
*/
function smarty_modifier_highlight_char($string,$css_class,$tag_name="span")
{
// strip whitespace off the front of the string, and make sure
// there are characters in the string, we only return valid characters...
if ( ($s = trim($string)) != '' )
{
$html = "<$tag_name";
if ( $css_class != 'none' ) $html .= ' class="'.$css_class.'"';
$html .= '>'.substr($s,0,1)."</$tag_name>".substr($s,1);
return $html;
}
else
{
return '';
}
}
?>
|
_________________ Technical Manager,
FormFunction
http://www.formfunction.co.za
Bespoke Application Solutions |
|
Back to top |
|
Adar Smarty Regular
Joined: 27 May 2004 Posts: 58
|
Posted: Fri May 28, 2004 12:13 am Post subject: |
|
|
nice one |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri May 28, 2004 6:20 am Post subject: |
|
|
Hi formfunction!
All contributions are certainly welcome--after all, this is a site for the community of users! Also feel free to post your plugin at the plugin page at the wiki.
Cheers and thanks! |
|
Back to top |
|
|
|
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
|