如何使用 ColdFusion 组件重用代码?

How to use a ColdFusion Component to re-use code?

我正在尝试使用组件在 ColdFusion 中组合页脚。我希望能够在我的整个应用程序中重复使用页脚,但只需编写一次页脚 HTML。

这是我到目前为止的内容,但我无法输出内容。

<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 | <a href="#" data-toggle="modal" data-target="#msgPrivacy"> Security and Privacy </a>
                </div>
            </div>
        </footer>
    </cffunction>
</cfcomponent>

<cfoutput>
    #getFooter#
</cfoutput>

我创建了一个cffidle here

像这样包装代码

<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 | <a href="##" data-toggle="modal" data-target="##msgPrivacy"> Security and Privacy </a>
                </div>
            </div>
        </footer>
</cfoutput>
</cfsavecontent>
<cfreturn footer>
    </cffunction>
</cfcomponent>

<cfoutput>
    #getFooter()#
</cfoutput>

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 | <a href="##" data-toggle="modal" data-target="##msgPrivacy"> Security and Privacy </a>
                    </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>