Code that makes me smile…

I guess I do have the heart of a coder if not the brain….

Been doing some website work, results of which are yet to be published, but I have utilised a couple of what I think are clever little code tricks, and where better to share them?!

First off we have a PR section on our site, and if I’m doing something wrong by identifying regular IT staff-dependant jobs and coding CMS-style solutions I apologise, but I do it anyway!  So this PR section is a list of the press releases the company puts out, sometimes there’s a glut, other times we don’t have anything for weeks.

In any case I coded a CMS page to allow others to create a new release (and dynamically generate a new page), kept it simple and restricted it to title, date posted (auto), a photo and the release itself. Once the beast that was the photo upload was tamed the process works nicely, but one thing that always defeated me was text layout.  The content was a simple copy/paste job, and for that part was being pasted into the form with the correct layout, obviously is was just a single line of text (with various wrapping results). Not nice, so with a little investigation the ASP function REPLACE saved the day;

<% variable=(db.Fields.Item(“content_field”).Value)%>
<% variable = replace(variable, chr(13), “<br>” ) %>
<% response.write (variable) %>

This assumes that you have opened your database at the appropriate record, a trick usually done by passing a variable in the url (check out http://www.islesofscilly-travel.co.uk/pr.asp?id=66 ) which is then used to select the required record from the database. The code above places the database field content into a variable before replacing any carriage return control codes with <br> (or carriage return in HTML speak) before pushing the output to the screen.

In years gone by I have seen situations where the same was accomplished by creating a separate field per paragraph and all kinds of other mess. I think this simple bit of code saves a lot of hassle, and if I’m honest think it looks pretty good in action!

Ok, so now I’m in my stride, shall we look at the second item??

This is less of a code trick and more of a CSS trick, but it certainly still qualifies as code that I like.  Probably 100 years behind everyone else, but I want dotted horizontal rules.  I’ve said it before, my web programming background means that I’m more of a coder than a designer, so anything that I find to improve the atheistic of a site I will use, to death!!

So I wanted something better than the boring standard rules, but didn’t want to bother putting in a graphic, or a squashed table, etc, then I stumbled across this;

hr {color: #fff; background-color: #fff; border: 1px dotted #ff0000; border-style: none none dotted; }

Added into a stylesheet (or inline if you wish!) this will make your generic hr’s appear just like this;


(well it would look right if WordPress didn’t strip out inline styles, you’ll just have to imagine a red, dotted, HR)

I know it’s daft, but it really is the little things….

Ahem – I showed you mine….

http://www.thatvoodooyoudo.com/css/styling-horizontal-rules/#comments

1 thought on “Code that makes me smile…

Leave a Comment

THE PERSONAL BLOG OF CORNWALL-BASED COMPANY DIRECTOR // CHRIS RICKARD