1
tzvook
Customizing the look of individuals blocks
  • 2008/12/5 16:21

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


A few of you probably knows my way of customizing the look of individuals blocks by giving them a custom title (posted here: https://xoops.org/modules/newbb/viewtopic.php?post_id=265122#forumpost265122 )

With this method I can name (title) blocks like
green-block + whatever title needed
red-block + whatever title needed
blue-block + whatever title needed

And those 3 blocks will look completely different (just by giving them a few characters in the begining of their title) ... via CSS and/or HTML each of those block can look different (so you can make a few "reusable blocks types" and use them whenever needed in your site blocks )

Well - this method won't work with UTF-8 (default in 2.3.x) since the smarty "truncate" is not working with UTF-8

I use this method a lot to give a few of my front-page blocks a unique look
( breaking the XOOPS look a bit )

There is a way to do it in UTF-8 too ( adding a smarty plugin to /xoops/class/smarty/plugins/ )

make a new file ( /class/smarty/plugins/modifier.mb_truncate.php ) with this code:
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty truncate modifier plugin
 *
 * Type:     modifier

 * Name:     mb_truncate

 * Purpose:  Truncate a string to a certain length if necessary,
 *           optionally splitting in the middle of a word, and
 *           appending the $etc string or inserting $etc into the middle.
 *           This version also supports multibyte strings.
 * @link http://smarty.php.net/manual/en/language.modifier.truncate.php
 *          truncate (Smarty online manual)
 * @author   Guy Rutenberg  based on the original
 *           truncate by Monte Ohrt 
 * @param string
 * @param integer
 * @param string
 * @param string
 * @param boolean
 * @param boolean
 * @return string
 */
function smarty_modifier_mb_truncate($string$length 80$etc '...'$charset='UTF-8',
                                  
$break_words false$middle false)
{
    if (
$length == 0)
        return 
'';

    if (
strlen($string) > $length) {
        
$length -= min($lengthstrlen($etc));
        if (!
$break_words && !$middle) {
            
$string preg_replace('/s+?(S+)?$/'''mb_substr($string0$length+1$charset));
        }
        if(!
$middle) {
            return 
mb_substr($string0$length$charset) . $etc;
        } else {
            return 
mb_substr($string0$length/2$charset) . $etc mb_substr($string, -$length/2$charset);
        }
    } else {
        return 
$string;
    }
}

/* vim: set expandtab: */
?>


..... I'll post the rest in here in an hour since I've been called in the middle of my post

2
tzvook
Re: Customizing the look of individuals blocks
  • 2008/12/5 16:56

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


I'm back

now ..... in your theme.html you can use it like this:

lets say we deal with the 'center-center block'

we can use it in our theme like this:

<div style="padding: 5px;">
<{if 
$block.title|mb_truncate:11:"":'UTF-8' == "green-block"}>
<{elseif 
$block.title|mb_truncate:9:"":'UTF-8' == "red-block"}>
<
div class="bl"><div class="br"><div class="tl"><div class="tr">
<{elseif 
$block.title != ""}>
<
div class="bl"><div class="br"><div class="ttl"><div class="ttr">
<
div style="font-size: 16px; color:#4b5676; font-weight: bold; vertical-align: middle; line-height: 34px; height:36px; background-image : url(<{xoImgUrl pix/divHeader.gif}>);"><img align="right" src="<{xoImgUrl pix/arrHeader.gif}>" width="13" height="35" alt="" hspace="12" border="0"><{$block.title}>div>
    <{/if}>
<
div class="blockContent"><{$block.content}>div>
div>div>div>div>
<
div class="clear">&nbsp;div>
div>


and it works like this
mb_truncate:9 (the number 9 here tels smarty to see if the 9 first chars of your block title equals to "red-block" and if it does - in the sample above it won't write the title, and will start the block with:

<div class="bl"><div class="br"><div class="tl"><div class="tr">


beginning your block title with "green-block" will simply give nothing (to block-title and no html) and so on ...

3
trabis
Re: Customizing the look of individuals blocks
  • 2008/12/5 22:37

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Interesting technique! Thanks for sharing

4
tzvook
Re: Customizing the look of individuals blocks
  • 2012/1/17 13:13

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


Came back after 3 years , to upgrade to 2.5.4 and use my own solution in a UTF site.
Nice to be back

Login

Who's Online

157 user(s) are online (110 user(s) are browsing Support Forums)


Members: 0


Guests: 157


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits