使用CFWheels中的layout、partials和includeContent()



我在试图获得静态内容、部分和布局以进行行为和显示时遇到了困难。我正在尝试创建:

  • 1个用于保存页眉/页脚数据的主布局
  • 主页的1个局部视图,因为它的主体布局不同
  • 1所有其他页面的局部视图

所有部分都应该输入到主布局中,我将在views/layout.cfm 下构建主布局

这是文件。

控制器/Home.cfc-包含索引和隐私功能

<cfcomponent extends="Controller">
    <cffunction name="index">
        <cfset qRecipes = model("tblRecipes").findAll(
            select="id, name, image, homepage_order",
            where="homepage_order > 0",
            order="homepage_order",
            maxrows=4
        ) />
     </cffunction>
     <cffunction name="privacy">
    </cffunction>
</cfcomponent>

views/home/index.cfm-应显示主页布局views/home/privaty.cfm-包含像这样用cfsavecontent包装的静态文本。

<cfsavecontent variable="foo">
xxxxxxxx
</cfsavecontent>
<cfset contentFor("foo") />

该文档没有提供足够深入的示例,使我能够理解我所缺少的内容。主布局将看起来像:

<cfoutput>#includePartial("/shared/header")#
#styleSheetLinkTag(source="homepage", head=true)#
</cfoutput>asdfsafd
    <body>
        <div id="page-wrap">
        <header>
            <cfoutput>#includePartial(partial="/shared/socialmedia", cache=1440)#</cfoutput>
            <nav id="top-navigation">
                <cfoutput>#includePartial("/shared/topnav")#</cfoutput>
            </nav>
        </header>
        <cfoutput>#includeContent()#</cfoutput> <!--- All partial data should output here --->
    </body>
</html>

由于我将所有用于隐私的文本放入一个变量中,在加载主布局之前,我是否需要另一个页面来输出#includeContent("foo")#?或者我可以让一页充满文本而不必用cfsavecontent包装吗?

没有必要将您的隐私页面包装在<cfsavecontent>中。尝试不使用<cfsavecontent>标签和contentFor("foo")。然后它的内容应该出现在主布局中#includeContent()#所在的位置。

你想用不同的主页做什么?任何东西

最新更新