我正在使用 Couch CMS,我将标题背景设置为可编辑区域,然后当我从管理页面更改图像时,新图像仅出现在主页中,尽管在其他页面中我使用它
<?php echo file_get_contents("header.php"); ?>
index.php 中的代码:
<?php require_once('admin/cms.php'); ?>
<cms:template title = 'English Home Page'>
<cms:editable name='header' type='image' />
</cms:template>
<?php echo file_get_contents("header.php"); ?>
<?php COUCH::invoke(); ?>
header.php 中的代码
<?php require_once( 'admin/cms.php' ); ?>
.site-header {
background-image: url("<cms:show header />");
background-repeat: no-repeat;
background-position: center;
background-attachment: notdefined;
background-clip: padding-box;
background-size: cover;
background-origin: padding-box;
}
<?php COUCH::invoke(); ?>
为什么当我在除索引之外的其他页面中获取标题页面内容时图像没有变化??
最佳答案
您实际上不需要将“ header ”用作成熟的模板(因为我不认为应该使用其 URL 通过浏览器直接访问它)。 相反,它应该被转换成一个“片段”,然后可以包含在其他模板中。
为此,请使用以下内容创建名为“header.html”的文本文件,然后将此文件放入 Couch 安装的“snippets”文件夹中(在您的系统中似乎已重命名为“admin”)案件)。请注意没有 <?php require_once('admin/cms.php'); ?>
或 <?php COUCH::invoke(); ?>
在片段中是必需的。
.site-header {
background-image: url("<cms:get_custom_field 'header' masterpage='index.php' />");
background-repeat: no-repeat;
background-position: center;
background-attachment: notdefined;
background-clip: padding-box;
background-size: cover;
background-origin: padding-box;
}
接下来,在您希望包含标题的所有模板中,使用以下语句
<cms:embed 'header.html' />
因此,例如,您的 index.php 模板现在将变成这样 -
<?php require_once('admin/cms.php'); ?>
<cms:template title = 'English Home Page'>
<cms:editable name='header' type='image' />
</cms:template>
<cms:embed 'header.html' />
<?php COUCH::invoke(); ?
希望这对您有所帮助。
关于php - 标题背景图像不会在 cms 的所有页面中更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41954205/