Using Smarty’s count_words and count_characters in design

This product page inspired me to write this post. It was launched around February last year (uh oh time flies!) and the first successful order was made around that time too. By then, there were only about 20 products or less, and really short attributes i.e. volumes in 8, 12 or 16 oz. strength like mild, regular, etc. Last monday, new products came in for addition to the site and they have quite longer attributes. It could have had a liquid width on the attribute and cart buttons but they had a really good design advisers and wanted to follow the design to the pixel.

Initially, this html code composes the product attribute and cart button, notice that <span class="c">Cherry</span> is a one word attribute for scent

Cherry 8 oz. $5.99 Add to bag » ITEM: 33404

And the new ones came with the colors “Casino Red”, “Golden Chestnut” and “Orchid Black” – long attributes, and two others “Copper” and “Spice” – short and manageable, as the column width will fit the entire word.

I was really planning to rewrite the whole attribute and cart button section, but I didn’t had much time. I figured I can make the font smaller and paddings or margins can go smaller than the regular so that two lines would fit in the box if the attribute value is a word longer. But I cannot be in PHP, its not really the way to go. So, if I can add another class that would override existing font-size and parent margin/padding, that would work. Here, I thought, word count doesn’t really need be in the PHP side and since I’m using Smarty, I found in it a variable modifier that can print the number of words in a variable, and that’s it. I can add another class in the column span like words-10 or countwords-3 in my template by the number of words that is present in the variable. Below is the generated code

Casino Red 8 oz. $11.39 Add to bag » ITEM: 33825

CSS rules

/* default rules */
.cartbutton { height: 23px; background: url('/images/button-add-to-bag.gif') no-repeat left center; color: #333; }
.cartbutton span { display: block; text-align: center; float: left; font-weight: bold; font-size: 10px; padding-top: 5px; }
.cartbutton span.c { width: 45px;  }
.cartbutton span.d { width: 80px;}
.cartbutton span.d a { color: #fff; text-decoration: none; }
.cartbutton span.e { margin-left: 10px; width: 100px; }
/* special rule for two word attribute */
span.words-2 { padding-top: 3px; line-height: 98%; font-size: 9px; }

And this is how it is setup in the template.

{if $attr[at].color} {$attr[at].color} {/if} {if $attr[at].strength} {$attr[at].strength} {/if} {if $attr[at].scent} {$attr[at].scent} {/if} {if $attr[at].volume} {$attr[at].volume} {/if} $ {if !$attr[at].amount} {$results[r].amount} {else} {math equation="x" x=$attr[at].amount format="%.2f"} {/if} Add to bag » ITEM: {if $results[r].sku && !$attr[at].sku}{$results[r].sku}{elseif $attr[at].sku}{$attr[at].sku}{/if}

Those extra class names like col-volume, col-scent and col-strength are only for future use, who knows what other formatting and adjustments on the data and theme will happen. Its really fun working with MVC model. Hope it helps :)

Happy coding!

Not matching charset reloads page twice

I noticed this when I uploaded an entire project files from dev server to production server. Using Web Developer plugin for Firefox, I had a clue to compare the Content-Type from the response header and the one I have in <meta> tags in my HTML.

Date: Wed, 25 Nov 2009 01:32:28 GMT
Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.7 with Suhosin-Patch
X-Powered-By: PHP/5.2.4-2ubuntu5.7
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 6572
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8

200 OK

And it was really it! Though they both have text/html, they had different character set values. Server responses with ISO-8859-1, but the <meta> instructs the browser to use utf-8, as it is declared in the document.

And so the second load of page occurs, its sort of trying to correct page encoding on the client-side. In the script I was working, I needed to pass some session values to the next page and clear it on page load, but when it reloads the second time, the session value had been emptied.

Hope it helps.

List of Philippine Holidays for 2010

Regular Holidays

  • New Year’s Day – January 1 (Friday)
  • Maundy Thursday / Good Friday – April 1 / 2 (Thursday / Friday)
  • Araw ng Kagitingan – April 9 (Friday)
  • Labor Day – May 1 (Saturday)
  • Independence Day – June 14 (Monday), moved from June 12
  • National Heroes Day – August 30 (Monday)
  • Bonifacio Day – November 29 (Monday), moved from November 30
  • Christmas Day – December 25 (Saturday)
  • Rizal Day – December 27 (Monday), moved from December 30

Special (non-working) holidays

  • Ninoy Aquino Day – August 23 (Monday), moved from August 21
  • All Saints’ Day – November 1 (Monday)
  • Christmas Eve – December 24 (Friday)
  • New Year’s Eve – December 31 (Friday)

Others

  • 1986 EDSA People Power Revolution anniversary – Special holiday for schools – February 22 (Monday), moved from February 25
  • Eid’l Fitr and Eid’l Adha 2010 – To be announced later
  • Founding Anniversary of Iglesia ni Cristo – July 27, 2010 – Special national working holiday

Source : http://www.pinoymoneytalk.com/philippine-holidays-2008/

Almost enchanted

It’s always great to visit EK, but on a holiday season, you might spend hours waiting in-line for each ride as there are lots of people during holiday. It’s alright anyway, kids had fun.

Out passed 1 a.m. from EK, heavy meals in a fast food along SLEX by 2 a.m. and home by 4 a.m.

“Salamuch”

Salamuch (sala-much)
Salamat in Filipino is the way of saying “thank you”, and I mixed it up with “thank you so much”, so it goes …

For those who greet thru IM, wall posts, SMS and email, family and friends, thank you! And those who personally did, thanks again! For my baby, I love you so much, and so grateful spending it with you this year and the pasts, thank you so much!

Uh-oh, another year in the 30′s! Merry Christmas everyone!

Christmas is, of course, the time to be home – in heart as well as body
~ Garry Moore

Torrent session via terminal

I’ve been looking on how to start a torrent session on another machine lately (on *nix flavor), and I thought there’s probably a command-line for it, and I was right. Since I can SSH thru in my Ubuntu machine at home, this sounds like a fit option.

The need arises when I’m in the office, working of course, and a movie title suddenly pops in my head and I get eager watching it. So I’d search for torrent for that movie with good remarks, at least watchable quality. Download it then SCP that to my machine at home and start session torrent on CLI. Takes at least a minute of my time to fire it up, but most importantly, it’s finished downloading when I get home. And watch on dinner I guess.

So, if you’re using Ubuntu, transmission is commonly installed there. But we need the transmission-cli package installed, which includes transmission-daemon and transmission-remote for starting CLI torrent session. First fire up the daemon, then use remote to add torrent file, like this one below

marvin@localhost:~/Desktop$ transmission-daemon
marvin@localhost:~/Desktop$ transmission-remote -a Avatar-2009-TELESYNC-XviD-ORC.torrent

If it says The program 'transmission-daemon' is currently not installed, just type the suggested install command. It should be like this

marvin@localhost:~$ sudo apt-get install transmission-cli

Now, if you want to find out download stats just add the -l or --list like the one below, will list all torrents and status.

marvin@localhost:~/Desktop$ transmission-remote -l

Use transmission-remote --help for other options. You can set upload and download limits too.

Here are useful links: