Skip to content

Instantly share code, notes, and snippets.

@nolandubeau
Created January 25, 2013 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolandubeau/af9aaf2f50d903537361 to your computer and use it in GitHub Desktop.
Save nolandubeau/af9aaf2f50d903537361 to your computer and use it in GitHub Desktop.
HTMLHelper.cfc
<!--- link --->
<cffunction name="link" output="false" access="public" returntype="any" hint="Create link tags, using the SES base URL or not">
<cfargument name="href" type="any" required="true" hint="The href link to link to"/>
<cfargument name="rel" type="any" required="false" default="stylesheet" hint="The rel attribute"/>
<cfargument name="type" type="any" required="false" default="text/css" hint="The type attribute"/>
<cfargument name="title" type="any" required="false" default="" hint="The title attribute"/>
<cfargument name="media" type="any" required="false" default="" hint="The media attribute"/>
<cfargument name="noBaseURL" type="boolean" required="false" default="false" hint="Defaults to false. If you want to NOT append a request's ses or html base url then set this argument to true"/>
<cfargument name="charset" type="any" required="false" default="UTF-8" hint="The charset to add, defaults to utf-8"/>
<cfargument name="sendToHeader" type="boolean" required="false" default="true" hint="Send to the header via htmlhead by default, else it returns the content"/>
<cfscript>
var buffer = createObject("java","java.lang.StringBuffer").init("<link");
// Check if we have a base URL
arguments.href = prepareBaseLink(arguments.noBaseURL,arguments.href);
//exclusions
local.excludes = "noBaseURL";
if(structKeyExists(arguments,'rel')){
if(arguments.rel == "canonical"){
local.excludes &= ",type,title,media,charset";
}
}
// build link
flattenAttributes(arguments,local.excludes,buffer).append('/>');
//Load it
if( arguments.sendToHeader AND len(buffer.toString())){
$htmlhead(buffer.toString());
}
else{
return buffer.toString();
}
</cfscript>
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment