I'm trying to put together a footer in ColdFusion using a component. I want to be able to re-use the footer throughout my application, but only have to write the footer HTML once.
Here's what I have so far, but I'm unable to output the content.
<cfcomponent>
<cffunction name="getFooter" access="public" returntype="string" output="yes">
<footer>
<div class="row text-center">
<div class="col-sm-12">
Copyright © 2020 Company Name | Security and Privacy
</div>
</div>
</footer>
</cffunction>
</cfcomponent>
<cfoutput>
#getFooter#
</cfoutput>
I created a cffidle here.
Footer.cfc
<cfcomponent>
<cffunction name="getFooter" access="public" returntype="string" output="no" >
<!--- chr(169) is the copyright symbol --->
<cfset var footer=
'<footer>
<div class="row text-center">
<div class="col-sm-12">
Copyright #chr(169)# 2020 Company Name | Security and Privacy
</div>
</div>
</footer>'>
<cfreturn footer>
</cffunction>
</cfcomponent>
testPage.cfm
<!---<cfprocessingdirective pageencoding="utf-8">---> <!---Optional, as UTF-8 encoding is usually the default --->
<cfset footerObject=new Footer()>
<cfset footer=footerObject.getFooter()>
<cfoutput>#footer#</cfoutput>
wrap the code like this
<cfcomponent>
<cffunction name="getFooter" access="public" returntype="string" output="yes">
<cfsavecontent variable="footer">
<cfoutput>
<footer>
<div class="row text-center">
<div class="col-sm-12">
Copyright © 2020 Company Name | Security and Privacy
</div>
</div>
</footer>
</cfoutput>
</cfsavecontent>
<cfreturn footer>
</cffunction>
</cfcomponent>
<cfoutput>
#getFooter()#
</cfoutput>
Related
Using ColdFusion 2018, and trying to add a progress bar on an API call.Created a cfc function to fetch this API details. For this called a "getStatus()" function through bind params. And able to load the cfprogress bar successfully. The problem is that I need to pass an en extra parameter to this getstatus function . Is it possible?
Please see the sample code I tried to load cfprogressbar
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<script type="text/javascript">
function startProgress() {
ColdFusion.ProgressBar.start("mydataProgressbar");
};
function onfinish() {
alert("Done");
};
</script>
<body>
<cfif IsDefined("Session.STATUS")>
<cfscript>
StructDelete(Session,"STATUS");
</cfscript>
</cfif>
<cfset sjsondata = '{"name":"Jibin","id":"1234"}'>
<!--- For code simplicity, formatting is minimal. --->
<cfform name="kitform">
<p>To make our service better and to benefit from our special offers,
take a moment to give us your email address and send us a comment.</p>
<p>Name:
<cfinput type="text" name="name"> </p>
<p>E-mail:
<cfinput type="text" name="email"> </p>
<p>Comment:
<cftextarea name="cmnt"/></p>
<p>
<cfoutput>
<cfinput type="hidden" name="jsondata" value="#sjsondata#">
</cfoutput>
<cfinput type="button" name="bttn1" value="Send Comment"
onClick=startProgress()></p>
<!--- The progressbar control --->
<cfinput type="button" name="bttn2" value="Send Comment 2"
onClick=startProgress2()></p>
<div style="padding-left:3px" >
<cfprogressbar name="mydataProgressbar"
bind="cfc:progressbar.getstatus({jsondata})"
interval="1700"
width="200"
oncomplete="onfinish"/>
</cfform>
</body>
</html>
File progressbar.cfc
<cfcomponent name="progressbar">
<cffunction name="getstatus" access="remote">
<cfargument name="jsonData" type="string" required="false">
<cfset str = StructNew()>
<cfset str.message = "Saving Data">
<cfif NOT IsDefined("session.STATUS")>
<cfset session.STATUS = 0.1>
<cfscript>
Sleep(200);
</cfscript>
<cfelseif session.STATUS LT 0.9>
<cfset session.STATUS=session.STATUS + .1>
<cfscript>
Sleep(200);
</cfscript>
<cfelse>
<cfset str.message = "Done...">
<cfset session.STATUS="1.0">
</cfif>
<cfset str.status = session.STATUS>
<cfreturn str>
</cffunction>
</cfcomponent>
Question 1: Is there a way to pass parameter to cfprogressbar getstatus() function?
Question 2: Is there any other alternative method to implement this process in progressbar.
Disclaimer, I'm a ColdFusion newbie...
I'm using Mura CMS 6, and I've got a question with regards to accessing a custom attribute.
My contentRenderer.cfc file has code for a Bootstrap Carousel. I'd like to be able to output the contents of a custom attribute on the file that the carousel is using, but I'm not entirely sure how to do that.
My custom attribute is named 'imageLink', but I have no idea how to get the current context to be able to output the contents of this attribute to the screen.
The following code is the code for the carousel (I didn't write it)
<cfsavecontent variable="local.str"><cfoutput>
<!--- BEGIN: Bootstrap Carousel --->
<!--- IMPORTANT: This will only output items that have associated images --->
<cfset local.feed = variables.$.getBean('feed').loadBy(name=arguments.feedName)>
<cfset local.iterator = local.feed.getIterator()>
<cfif local.feed.getIsNew()>
<div class="container">
<div class="alert alert-info alert-block">
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button>
<h4>Ooops!</h4>
The <strong>#HTMLEditFormat(arguments.feedName)#</strong> Content Collection/Local Index does not exist.
</div>
</div>
<cfelseif local.iterator.hasNext()>
<div id="#arguments.cssID#" class="carousel slide" data-interval="#arguments.interval#">
<!--- Indicators --->
<cfif arguments.showIndicators>
<ol class="carousel-indicators">
<cfset local.iterator.reset()>
<cfset local.idx = 0>
<cfloop condition="local.iterator.hasNext()">
<cfset local.item=iterator.next()>
<cfif ListFindNoCase('jpg,jpeg,gif,png', ListLast(local.item.getImageURL(), '.'))>
<li data-target="###arguments.cssID#" data-slide-to="#idx#" class="<cfif local.idx eq 0>active</cfif>"></li>
<cfset local.idx++>
</cfif>
</cfloop>
</ol>
</cfif>
<!--- Wrapper for slides --->
<div class="carousel-inner" role="listbox">
<cfset local.iterator.reset()>
<cfset local.idx = 0>
<cfloop condition="local.iterator.hasNext()">
<cfset local.item=iterator.next()>
<cfif ListFindNoCase('jpg,jpeg,gif,png', ListLast(local.item.getImageURL(), '.'))>
<div class="item<cfif local.idx eq 0> active</cfif>">
<img src="#local.item.getImageURL(argumentCollection=local.imageArgs)#" alt="#HTMLEditFormat(local.item.getTitle())#">
<cfif arguments.showCaption>
<div class="container">
<div class="carousel-caption">
<h2>#HTMLEditFormat(local.item.getTitle())#</h2>
#local.item.getTitle()#
<!-- <p><a class="btn btn-larg btn-primary" href="#local.item.getURL()#">Read More</a></p>-->
</div>
</div>
</cfif>
</div>
<cfset local.idx++>
</cfif>
</cfloop>
</div>
<cfif local.idx>
<!--- Controls --->
<cfif local.idx gt 1>
<a class="left carousel-control" href="###arguments.cssID#" data-slide="prev" role="button">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="###arguments.cssID#" data-slide="next" role="button">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
<!--- AutoStart --->
<cfif arguments.autoStart>
<script>jQuery(document).ready(function($){$('###arguments.cssID#').carousel({interval:#arguments.interval#});});</script>
</cfif>
</cfif>
<cfelse>
<div class="alert alert-info alert-block">
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button>
<h4>Oh snap!</h4>
Your feed has no items <em>with images</em>.
</div>
</cfif>
</div>
<cfelse>
<div class="alert alert-info alert-block">
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button>
<h4>Heads up!</h4>
Your feed has no items.
</div>
</cfif>
<!--- // END: Bootstrap Carousel --->
</cfoutput></cfsavecontent>
How can I access the current context to output that attribute?
Here are the docs on how to display them.
http://docs.getmura.com/v6/back-end/class-extension-manager/displaying-extended-attributes/
It looks like you looping through a collection of content so I believe this would work.
#local.item.get("imageLink")#
Assuming you are working within the cfloop and after the line
<cfset local.item=iterator.next()>
You can get your custom imageLink value using
#local.item.getImageLink()#
or
#local.item.getValue('imageLink')#
I'm having trouble with my ColdFusion code. I'm trying to create a simple HTML select form using cfloop to populate the options. it works, and when you select an option, it pulls that option from the db. but once you do that, the only option available is the option previously selected. What am I doing wrong?
<!--- Query the DataBase --->
<cfparam name="url.colors" default="">
<cfif structKeyExists(form, "colordb")>
<cfset url.colordb = form.colordb>
</cfif>
<cfquery datasource="bentest" name="colors">
SELECT *
FROM color_codes
<cfif structKeyExists(url,"colordb") and isNumeric(url.colordb)>
WHERE id=#url.colordb#
</cfif>
</cfquery>
<!--- Add Selector for user to select a color --->
<div class="selector">
<cfoutput>
<form action="?contentId=colorPickdb" name="clr" method="post" class="clr">
<select class="clr" name="colordb" onChange="submit();">
<option selected>Select A Color!</option>
<cfloop query="colors">
<option value="#colors.id#">#colors.color#</option>
</cfloop>
</select>
</form>
</cfoutput>
</div>
<div class="dump">
<!--- Output results of Query --->
<p><cfif structKeyExists(form, "colordb")>
<cfoutput query="colors">
#colors.color# <br>
#colors.hexvalue# <br><br>
</cfoutput>
</cfif>
<br>
</p>
</div>
You can use query of query here.
<!--- Query the DataBase --->
<cfparam name="url.colors" default="">
<cfquery datasource="bentest" name="colors">
SELECT *
FROM color_codes
</cfquery>
<!--- Add Selector for user to select a color --->
<div class="selector">
<cfoutput>
<form action="?contentId=colorPickdb" name="clr" method="post" class="clr">
<select class="clr" name="colordb" onChange="submit();">
<option selected>Select A Color!</option>
<cfloop query="colors">
<option value="#colors.id#">#colors.color#</option>
</cfloop>
</select>
</form>
</cfoutput>
</div>
<div class="dump">
<!--- Output results of Query --->
<p>
<cfif structKeyExists(form, "colordb")>
<cfquery dbtype="query" name="colorSelected">
SELECT *
FROM colors
WHERE id=#form.colordb#
</cfquery>
<cfoutput query="colorSelected">
#colorSelected.color# <br>
#colorSelected.hexvalue# <br><br>
</cfoutput>
</cfif>
<br>
</p>
</div>
I am trying to add a new page called result.cfml to the ColdFusion website. This page(result.cfml) contains all basic Html tags and displays inside main.cfml. I see other page( result2.cfml) has the same setup, and it works fine inside main.cfml. However, I am not be able to view the page(result.cfml). So do i have to register this result.cfml within main.cfml?
Here is an error that i got when calling the result.cfml. Please help me.
The IDPAGE argument passed to the getPage function is not of type numeric.
If the component name is specified as a type of this argument, it is possible that either a definition file for the component cannot be found or is not accessible.
main.cfml
<div><img src="/images/titles/<cfoutput>#session.language#</cfoutput>/stepfinal.png" usemap="#STEPS" /></div>
$box:final$
final.cfml
<form action="<cfoutput>#application.site.index#</cfoutput>" method="post">
<input name="event" type="hidden" value="update-final" />
<input name="tpPayment" type="hidden" value="A" />
<button type="submit" style="height:30"></button>
</form>
<form action="<cfoutput>#application.site.index#</cfoutput>" method="post">
<input name="event" type="hidden" value="update-final" />
<input name="tpPayment" type="hidden" value="B" />
<button type="submit" style="height:30"></button>
</form>
update-final.cfml
<cfif form.tpPayment is "B">
<cflocation addtoken="no" url="#application.site.index#/page/result"/>
</cfif>
<cfif form.tpPayment is "A">
<cflocation addtoken="no" url="#application.site.index#/page/result2"/>
</cfif>
result.cfml
<h1>Title1</h1>
<p>some other paragraphs here</p>
result2.cfml
<h1>Title2</h1>
<p>some other paragraphs here</p>
getPage() function
<cffunction name="getPage" access="public" returntype="query" output="no">
<cfargument name="idPage" type="numeric" required="no">
<cfquery name="qryPage" datasource="#application.global.dsn#">
Select idPage
, idTemplate
, idSection
, nmPage
, nmFile
, tpFile
, dsTitle
, dsTitleContent
, stPage
, flMenu
, nmMenu
, flSiteMap
, dsContentTitle
, dsPage
, dtSchedule
, dtExpire
, flProtected
, cdGrantedKeys
, dtCreate
, dtLastUpdate
From Page
<cfif IsDefined("arguments.idPage")>
Where idPage = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.idPage#">
</cfif>
Order by nmPage
</cfquery>
<cfreturn qryPage>
I have three select boxes: State, District, School. The first two work great if I don't have the school, but the school is actually the important part. Without the school select everything works fine. With the school box I get the error:
Bind failed, element not found: pid
CFC
<cfcomponent>
<cfset THIS.dsn="whatever">
<cffunction name="getDistricts" access="remote" returntype="query">
<cfargument name="state" required="yes" hint="The districts are in this state." />
<cfstoredproc datasource="#THIS.dsn#" procedure="getSchoolAndDistrict" returncode="yes">
<cfprocparam cfsqltype="cf_sql_varchar" dbvarname="#mstate" value="#arguments.state#" type="in">
<cfprocresult resultset="1" name="districts">
</cfstoredproc>
<cfreturn districts>
</cffunction>
<cffunction name="getSchools" access="remote" returntype="query">
<cfargument name="state" required="yes" hint="The districts are in this state." />
<cfargument name="pid" required="yes" hint="The district pid." />
<cfstoredproc datasource="#THIS.dsn#" procedure="getSchoolAndDistrict" returncode="yes">
<cfprocparam cfsqltype="cf_sql_varchar" dbvarname="#mstate" value="#arguments.state#" type="in">
<cfprocparam cfsqltype="cf_sql_varchar" dbvarname="#pid" value="#arguments.pid#" type="in">
<cfprocresult resultset="2" name="schools">
</cfstoredproc>
<cfreturn schools>
</cffunction>
</cfcomponent>
CFM
<cfoutput>
<cfform action="#CGI.PATH_INFO#" name="testdistricts" method="post">
<cfselect name="states" query="states"
queryPosition="below"
display="state" value="state">
<option value="">State</option>
</cfselect>
<cfselect name="districts"
bind="cfc:cfcs.getDistricts.getDistricts({states})"
queryPosition="below"
display="name" value="pid" bindonload="no">
<option value="">District</option></cfselect>
<cfselect name="schools"
bind="cfc:cfcs.getDistricts.getSchools({pid})"
queryPosition="below"
display="name" value="pid" bindonload="no">
<option value="">School</option>
</cfselect>
<br> <br>
<cfinput type="submit" name="submit" value="Submit">
</cfform>
</cfoutput>
Your problem is that the Schools select is bound to the value of the selected option instead of being bound to the district control itself...
<cfform action="#CGI.PATH_INFO#" name="testdistricts" method="post">
<cfselect name="states" query="states"
queryPosition="below"
display="state" value="state">
<option value="">State</option>
</cfselect>
<cfselect name="districts"
bind="cfc:cfcs.getDistricts.getDistricts({states})"
queryPosition="below"
display="name" value="pid" bindonload="no">
<option value="">District</option></cfselect>
<cfselect name="schools"
bind="cfc:cfcs.getDistricts.getSchools({districts})"
queryPosition="below"
display="name" value="pid" bindonload="no">
<option value="">School</option>
</cfselect>
<br> <br>
<cfinput type="submit" name="submit" value="Submit">
</cfform>
This is where your problem is
bind="cfc:cfcs.getDistricts.getSchools({districts})"