-
-
Save nolandubeau/af9aaf2f50d903537361 to your computer and use it in GitHub Desktop.
HTMLHelper.cfc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- 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