1

我正在尝试使用一个组件在 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

4

2 回答 2

2

页脚.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>

测试页面.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>
于 2020-07-23T10:53:08.280 回答
1

像这样包装代码

<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>
于 2020-07-23T00:24:26.870 回答