0

I wish to add some script to a view and have it que and load at the bottom of the page within the default layout. At the moment it runs before query is loaded and causes an error.

I am using cakephp 2.5

Is there a way to buffer it?

myview.ctp:

<script type="text/javascript">
  FWDEVPUtils.onReady(function(){

  FWDEVPlayer.useYoutube = "yes";
  FWDEVPlayer.videoStartBehaviour = "pause";

  new FWDEVPlayer({   
    //main settings
    instanceName:"player",
    parentId:"player",
    mainFolderPath:"content"
  });
});

default.ctp

echo $this->Html->script('//code.jquery.com/jquery-1.10.2.min.js');
echo $this->Html->script('bootstrap.min');
echo $this->Html->script('FWDEVPlayer');

echo $this->fetch('script');
echo $this->Js->writeBuffer();

1 Answer 1

2

In myview.ctp:

<?php $this->start('script'); ?>
<script type="text/javascript">
  FWDEVPUtils.onReady(function(){

  FWDEVPlayer.useYoutube = "yes";
  FWDEVPlayer.videoStartBehaviour = "pause";

  new FWDEVPlayer({   
    //main settings
    instanceName:"player",
    parentId:"player",
    mainFolderPath:"content"
  });
});
<?php $this->end(); ?>

You script will then be included in your layout default.ctp where you wrote: echo $this->fetch('script');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.