Posts tagged as Quick Tips

Using include within cfscript

I’ve only recently started using cfscript to code my components, and today ran into this little problem…

I have an Application.cfc, written in cfscript, and I want it to include a settings file which contains the different settings between development and production servers (so I can update the Application.cfc file without having to worry about altering settings before copying it to the live server).

It looks something like this (simplified, of course!):

component output="false"
{
	this.name = "myApp";
	this.sessionManagement = true;
	this.ormEnabled = true;
	this.datasource = "myDatasource";
	include "/config/serversettings.cfm";
}

And the settings file it included was this:

// Server settings for dev server
this.ormSettings.logSQL = true;

I couldn’t work out why the logging setting was not being seen. By trial and error with other script-based includes, I discovered the answer:

I’d assumed that, like a normal cfinclude, it would just take the contents of the included file and placed them in place of the include call – so, because I was already within cfscript, it would see the code in the included file as just another piece of cfscript to run.

This doesn’t seem to be the case. By changing the included file to this:

<cfscript>
// Server settings for dev server
this.ormSettings.logSQL = true;
</cfscript>

…it worked perfectly. It would appear that, even if you’re calling an include from within a cfscript block, it doesn’t see what’s included as cfscript unless you explicitly define it as such.

I suppose it makes sense – otherwise you’d never be able to include traditional CFML tags from within cfscript – but it caught me out; I hope this is helpful to anyone else who is caught out by it!

1 comment Posted on 22 August, 2010, in ColdFusion, Quick Tips

Serving web fonts from IIS

I’ve just started playing with web fonts for a site redesign. I came across the following gotcha (thanks, Firebug, for alerting me to it!).

If you are running IIS 6 or higher on your web server, some of the fonts will be disabled by default.

Your typical @font-face declaration might look like this:

This will deliver one of four different font formats, depending on your browser’s capabilities. (The font is Vegur, a really nice-looking free font I found over at Font Squirrel).

By default, the MIME types in IIS 6 are configured to deliver EOT (as used by IE) and TTF files. But WOFF (Firefox) and SVG (iPhone, iPad & others) will not be served.

Simply add the following MIME type declarations via IIS Manager (HTTP Headers tab of website properties):

.woff  application/x-woff
.svg   image/svg+xml

…and everything should work fine.

No comments Posted on 10 April, 2010, in CSS, Quick Tips

Stop mail clients auto-linking text as URLs

Wow – it’s been a while since I last posted…

This is just a quickie – a reminder for my own reference, but could also be useful to others.

I’m building a shop, and the email confirmations include the line:

Your credit card statement will show a payment to "MYDOMAIN.COM".

Which is fine, except that many mail clients (e.g. Apple Mail) will take MYDOMAIN.COM and link it as a URL – which I don’t want.

To avoid this, simply add a zero width space into the “URL” – for instance:

Your credit card statement will show a payment to "MYDOMAIN&#8203;.COM".

(That’s the HTML version. If you’re generating a plain text alternative (using CFML, of course), you’ll want to use #Chr(8203)#).

The text will now look identical – except it will not be linked by the mail client.

2 comments Posted on 9 February, 2010, in HTML, Quick Tips

Handling initial display states for jQuery-enhanced pages

When building a jQuery-enhanced site (or using any other JavaScript library, for that matter) I find one of the tasks I use jQuery for is to set the initial display states of various elements on the page.

For instance, you may have some elements that should only be displayed if JavaScript is enabled; and some which should be hidden. But what do you do to avoid the flash of unwanted content which may appear before various libraries load? Here's my solution...

Read more »

6 comments Posted on 26 August, 2009, in JavaScript, jQuery, Quick Tips