Bug with Block controller on_page_view?
Permalink
I am on 5.4.0.5.
I wrote a custom block.
I am trying to add some javascripts with bock controller - on_page_view, but they are not getting included.
If I add these block specific scripts in /concrete/elements/page_controls_header.php
then it works. But surely this is not the way to do this.
Any help is much appreciated.
I wrote a custom block.
I am trying to add some javascripts with bock controller - on_page_view, but they are not getting included.
If I add these block specific scripts in /concrete/elements/page_controls_header.php
then it works. But surely this is not the way to do this.
Any help is much appreciated.
I must add that I want this javascript in Edit mode. is any method I should use?
The problem is that until you have actually added the block, the blocks controller wont be called. So if you have the block already on the page, then edit it, the javascript should be included, but when you first add the block, it wont be.
The blocks auto.js will always be included, so if you can put your js in there, that will work. Alternatively, you could put your <script src=... line into your add.php file if that isn't too late in the chain.
Oh, and here's another option that's a bit different. I had a very similar problem a few weeks back, but I wanted to include a css file for the interface of the add.php. Currently, this css has to be in your main css file, which means it's included all the time - or it ends up being put directly into add.php which is invalid code. So my solution was this:
Hope something in there somewhere helps :)
Jon
The blocks auto.js will always be included, so if you can put your js in there, that will work. Alternatively, you could put your <script src=... line into your add.php file if that isn't too late in the chain.
Oh, and here's another option that's a bit different. I had a very similar problem a few weeks back, but I wanted to include a css file for the interface of the add.php. Currently, this css has to be in your main css file, which means it's included all the time - or it ends up being put directly into add.php which is invalid code. So my solution was this:
var filename = '/packages/jbx_zend_form/blocks/jbx_zend_form/assets/css/interface.css'; var fileref = document.createElement("link"); $(fileref).attr('rel', 'stylesheet'); $(fileref).attr('type', 'text/css'); $(fileref).attr('href', filename); $('head').append($(fileref));
Hope something in there somewhere helps :)
Jon
Thank you Jon for these leads.
I need to try one by one this weekend.
I will inform the results.
Hope something works out :)
Thanks again.
I need to try one by one this weekend.
I will inform the results.
Hope something works out :)
Thanks again.
> The problem is that until you have actually added
> the block, the blocks controller wont be called.
That's not true. The controller is loaded when adding and editing.
-Steve
> the block, the blocks controller wont be called.
That's not true. The controller is loaded when adding and editing.
-Steve
> I must add that I want this javascript in Edit mode.
Assuming you're using the addHeaderItem() method, put the code that loads the JS in a separate method of your controller and then call that method from both the add() and edit() methods of the controller.
Calling that method from on_page_view() should also load the JS during a normal page view. The auto.js file is for JS code that's needed ONLY when adding/editing a block but not during a normal page view. (IMO, for clarity, that file should be named addedit.js.)
-Steve
Assuming you're using the addHeaderItem() method, put the code that loads the JS in a separate method of your controller and then call that method from both the add() and edit() methods of the controller.
Calling that method from on_page_view() should also load the JS during a normal page view. The auto.js file is for JS code that's needed ONLY when adding/editing a block but not during a normal page view. (IMO, for clarity, that file should be named addedit.js.)
-Steve
Thanks Steve.
I need the javascripts on for add/edit. So I will try with auto.js.
But I want to create a block similar to
http://www.gamabhana.com/gamabhana_pro/...
for indian language, but the order of javascript is important.
will keep you posted.
I need the javascripts on for add/edit. So I will try with auto.js.
But I want to create a block similar to
http://www.gamabhana.com/gamabhana_pro/...
for indian language, but the order of javascript is important.
will keep you posted.
The following pages might help if you haven't already read them...
http://www.concrete5.org/documentation/developers/blocks/mvc-approa...
http://www.concrete5.org/documentation/developers/blocks/directory-...
-Steve
http://www.concrete5.org/documentation/developers/blocks/mvc-approa...
http://www.concrete5.org/documentation/developers/blocks/directory-...
-Steve
Don't use auto.js – use $this->addHeaderItem() from within the edit() and add() functions. Then those will be added to the page dynamically when the block is in add and edit mode.
Just curious, Andrew...
Is there any situation where one would actually NEED to use auto.js? I never use it, as I've found that the method you describe works fine and is more consistent with the way header items are added in other situations.
-Steve
Is there any situation where one would actually NEED to use auto.js? I never use it, as I've found that the method you describe works fine and is more consistent with the way header items are added in other situations.
-Steve
not really. It was a stopgap solution before we had addHeaderItem() working with add() and edit() (we would always just include auto.js whether it was there or not.) But the add() and edit() approach (once we added it later) was much more elegant.