Smarty Strip
posted on Thursday, October 30, 2008
If you are a Smarty expert then this will be very dumb. I knew about the cool Smarty tag, strip, but hadn't found a really good use for it. When you are using Smarty you are changing the how the HTML is created when the page is loaded. In some cases, how the code is formatted affects how the browser displays it, especially for IE. One of the most common areas I've seen this is when formatting using an indented structure and having an image at the end of a block. By having the closing block tag (/div, /td, etc.) on a new line an extra bit of space is added behind or below the image. This extra space is usually noticeable and causes page rendering differences among browsers. Here is an example of this piece of code:
<img src="myimage.gif" alt="" />
</div>
A workaround is to manually put the closing block tag on the previously line with no space like so:
<img src="myimage.gif" alt="" /></div>
This works fine but what if you don't want to do that or you want to keep your Smarty template file looking nice and tidy with all of your extra lines and indents? This is where the Smarty strip tag comes in. Just add strip around the block of code and all those unwanted spaces are stripped out:
{strip}
<img src="myimage.gif" alt="" />
</div>
{/strip}
This will build the page with the following source in that area:
<img src="myimage.gif" alt="" /></div>
This can also be useful if you are running through a loop building rows of a table. You might want to see the structure in a nice easy-to-read format but want the generated lines to be nice and tight. Just wrap it in strip:
<table ...>
{foreach ...}
{strip}
<tr>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
{/strip}
{/foreach}
</table>
This is nice to read and work with in the template but will generated the following tight source code when the page is loaded:
<table ...>
<tr><td>...</td><td>...</td><td>...</td><td>...</td></tr>
<tr><td>...</td><td>...</td><td>...</td><td>...</td></tr>
<tr><td>...</td><td>...</td><td>...</td><td>...</td></tr>
</table>
Yeah, you probably already knew this but I thought this was really useful. I used to build web apps using Mason and it had a simple way to suppress new lines so using strip is a nice substitute for that feature I used in Mason. Hope you find this useful! :)
Sales Tax
posted on Sunday, September 9, 2007
Yeah, I said it. Sales tax. It has to be one of the uglier sides of configuring online shopping carts. Now there are rumblings that some states are going to require that tax be collected by e-tailers for each state, county, city, or municipality. That is a lot of tax. No one seems to really know how it's supposed to work. Everyone seems to have a different opinion, including accountants. I'm not a tax expert, and work hard at keeping it that way, but I still have to work with it here and there.
Well, that time came again with a need to implement a country-wide sales tax based on all counties. I started with data for all counties in one state. Since I work exclusively with X-Cart, I was looking to convert a third-party zipcode sales tax table into the zone and tax tables. I ended up writing a perl script that parses the flat file. Here are the steps:
- Use Excel's Text-do-Data to convert the position-delimited table to useable columns.
- Come up with a key to name each tax zone. I used a format of ST-COUNTY (STate).
- Load the list of zones into the db to a) get them loaded and b) utilize the db auto-increment to generate zoneid's.
- Save the zoneid-zone as a csv.
- Leverage Perl's data handling to load in the zone csv and tax table csv into hashes, then spit out csv files for zone_elements and tax_rates. It's possible Excel could have been used to do this but that may have taken me just as long and not quite as fun.
- Import the two new csv files into their corresponding tables.
That's it! Now the tax data corresponding to customer zip code is working! Now when we get the data for the rest of the states I have a method ready to go.
If you need help implementing this solution, just let me know!
My New Blog
posted on Sunday, June 24, 2007
A look-at-my-new-blog post is pretty typical for a first post, but I really do want you to look at my new blog. It's because my awesome wife designed it as a surprise just for me! I had mentioned wanting to start a blog and she came up with this design. It's just another excellent example of her great sense of design and ability to setup blogger templates. Thanks Cherie!
Now, who's Joe? Joe is a nickname and I like my privacy so I try to stay away from personal details. I'm a Christian and put God, country, and family above all else. At times coding can become consuming so it is sometimes hard to keep things in perspective.
I first got my taste of coding in the 6th grade. The school had a computer class full of Apple IIe's where we learned how to play games, kick around a command line, paint, and write BASIC. I was hooked. Over the next few years I used the family PeeCee to continue to write simple BASIC programs and made some databases with dBase. I picked up C, Pascal, and Fortran books here and there. High School had a networked computer class where we learned some beginner C. I took Fortran and COBOL classes in college but never had a job writing code. So over the years I tinkered with various iterations of BASIC as a pastime all the while building PCs, loving Macs, and being your basic geek.
As the internet became prevalent, I ended up monitoring Unix systems for a large internet company in their NOC. This was my first taste of Unix. After I got my head around it, I learned shell scripting and wrote some dumb sysadmin scripts. When I took a couple Perl classes I really saw the power of coding to control systems, automate tasks, and consolidate reporting. To help learn, I went back and rewrote those shell scripts into Perl. I then earned Sys Admin certifications in Solaris 7 and 8, and HP-UX 10. After a few years of playing Sys Admin I moved to a division which worked on internal tools, some of which were web based. Since I was the resident sysadmin I was given the task of setting up some servers, cleaning up some internal web pages, and eventually became webmaster to some of these servers. Then I was tasked with writing a new internal web application using Mason. After not knowing whether to choose programming or webmaster as a career, I finally found I could have the best of both worlds developing web applications.
After leaving the company and branching out on my own, I was forced to learn PHP and eventually Smarty. I tried to say I was not a PHP developer but I've succumbed and definitely spend most of my time writing or modifying PHP code. Some folks don't like Smarty but after using it for a few years it is quite powerful and helps keep code and html separate.
If you haven't noticed by now, I love Wikipedia. It has to be the greatest information resource available to date. You can get lost clicking from one topic to another. It really is all there!
Having been a DOS guy way before I used a Mac and using various Unix systems over the years, my computer platform of choice is Apple with their Macintosh computers and amazing Mac OS X. If you haven't checked them out lately, you have to see this.
...and the designer of this blog used a Mac. Thanks for the new blog!
