Skip to content

Instantly share code, notes, and snippets.

Created December 20, 2012 19:29
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 anonymous/4347948 to your computer and use it in GitHub Desktop.
Save anonymous/4347948 to your computer and use it in GitHub Desktop.
Modified meta() function in ColdBox HTMLHelper plugin
<!--- meta --->
<cffunction name="meta" output="false" access="public" returntype="any" hint="Helps you generate meta tags">
<cfargument name="name" type="any" required="true" hint="A name for the meta tag or an array of struct data to convert to meta tags.Keys [name,content,type]"/>
<cfargument name="content" type="any" required="false" default="" hint="The content attribute"/>
<cfargument name="type" type="string" required="false" default="name" hint="Either ''name'' or ''equiv'' which produces http-equiv instead of the name"/>
<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 x = 1;
var buffer = createObject("java","java.lang.StringBuffer").init("");
var tmpType = "";
// prep type
if( arguments.type eq "equiv" ){ arguments.type = "http-equiv"; };
// Array of structs or simple value
if( isSimpleValue(arguments.name) ){
buffer.append('<meta #arguments.type#="#arguments.name#" content="#arguments.content#" />');
}
if(isArray(arguments.name)){
for(x=1; x lte arrayLen(arguments.name); x=x+1 ){
if( NOT structKeyExists(arguments.name[x], "type") ){
arguments.name[x].type = "name";
}
if( arguments.name[x].type eq "equiv" ){
arguments.name[x].type = "http-equiv";
}
buffer.append('<meta #arguments.name[x].type#="#arguments.name[x].name#" content="#arguments.name[x].content#" />');
}
}
//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