[英]How to modify $content_for_layout in CakePHP 1.3
I am using CakePHP 1.3.我正在使用 CakePHP 1.3。 In
app/views/layouts/default.ctp
I am using this:在
app/views/layouts/default.ctp
我使用这个:
<?php echo $content_for_layout;?>
According to CakePHP Application Development, by Ahsanul Bari and Anupom Syam,根据Ahsanul Bari 和Anupom Syam 的CakePHP 应用程序开发,
"This line is mainly responsible for placing controller-rendered view contents inside the layout. We must include this to tell Cake where to place the action-specific controller-rendered views."
“这一行主要负责将控制器渲染的视图内容放置在布局中。我们必须包括这一行来告诉 Cake 将特定于动作的控制器渲染的视图放置在哪里。”
I was trying to figure out how to modify the content of $content_for_layout
.我试图弄清楚如何修改
$content_for_layout
的内容。 But I guess that is not the kind of variable that I am supposed to modify to modify the layout.但我想这不是我应该修改以修改布局的那种变量。 What I am trying to accomplish is to either modify
$content_for_layout
or create a new layout to customize some elements for an A/B testing experiment.我想要完成的是修改
$content_for_layout
或创建一个新布局来自定义 A/B 测试实验的一些元素。 Could you help me to better understand how to manipulate $content_for_layout
?你能帮我更好地理解如何操作
$content_for_layout
吗? Thank you.谢谢你。
UPDATE 1:更新1:
I am configuring an A/B testing experiment.我正在配置 A/B 测试实验。 I have this in
app/views/layouts/default.ctp
:我在
app/views/layouts/default.ctp
有这个:
<body>
..........
<div id="split-test-homepage-content-original">
..........
<?php echo $content_for_layout;?>
..........
</div>
<div id="split-test-homepage-content-redesign">
..........
<?php echo $content_for_layout;?>
..........
</div/>
</body>
With CSS I am hiding/showing either split-test-homepage-content-original
or split-test-homepage-content-redesign
depending on the version that the split test will show.使用 CSS 我隐藏/显示
split-test-homepage-content-original
或split-test-homepage-content-redesign
取决于拆分测试将显示的版本。 But I am having problems because $content_for_layout
is being rendered twice.但是我遇到了问题,因为
$content_for_layout
被渲染了两次。 Even though visually people only see one version but behind the scenes the page has $content_for_layout
loading twice on the same page.即使在视觉上人们只看到一个版本,但在幕后,该页面在同一页面上加载了两次
$content_for_layout
。 This is causing all kinds of problems to me such as duplicate forms, JavaScript elements not working correctly as a result of duplicate variables, etc. What I want to do is to modify what $content_for_layout
does for <div id="split-test-homepage-content-redesign">
.这给我带来了各种各样的问题,例如重复的表单,由于重复变量而导致 JavaScript 元素无法正常工作等。我想要做的是修改
$content_for_layout
对<div id="split-test-homepage-content-redesign">
。 One option I am considering is to use JavaScript so that in the jQuery(document).ready(function($) {
section I can do something in the experiment so that if a variable contains a specific boolean value, I show one version or the other. Something like this:我正在考虑的一种选择是使用 JavaScript,以便在
jQuery(document).ready(function($) {
部分我可以在实验中做一些事情,以便如果变量包含特定的布尔值,我会显示一个版本或其他。像这样:
if(javascriptvariable==true){
then use the following HTML for the view: if(javascriptvariable==true){
然后为视图使用以下 HTML:
<div id="split-test-homepage-content-original">
..........
<?php echo $content_for_layout;?>
..........
</div>
else, the Javascript will take care of not displaying the above, but this:否则,Javascript 将处理不显示上述内容,但是:
<div id="split-test-homepage-content-redesign">
..........
<?php echo $content_for_layout;?>
..........
</div/>
Does the JavaScript approach make sense to you or should I do something about creating new layouts or modifying what $content_for_layout
does? JavaScript 方法对您有意义吗,或者我应该做些什么来创建新布局或修改
$content_for_layout
作用? Thank you.谢谢你。
Duplicating content was definitely asking for trouble.复制内容绝对是自找麻烦。 I used a much better approach to manipulate CSS classes and ids only without duplicating content.
我使用了一种更好的方法来操作 CSS 类和 id,而不复制内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.