Extension documentation - How to embed scripts in the <head> of the admin
This is an open discussion with 5 replies, filed under Extensions.
Search
Rowan’s Publish Filtering ext. might be worth checking out. It’s limited to the same page you’re after.
I noticed that the multiselect_to_checkboxes extension is more specific when embedding links in the head. I think it only adds the links to a new and edit entry pages.
Here’s the extension.driver.php of that extension:
public function __appendAssets($context){ if(isset(Administration::instance()->Page->_context['section_handle']) && in_array(Administration::instance()->Page->_context['page'], array('new', 'edit'))){ Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/multiselect_to_checkboxes/assets/mtoc.css', 'screen', 221); Administration::instance()->Page->addScriptToHead(URL . '/extensions/multiselect_to_checkboxes/assets/jquery.symphony.mtoc.js', 222); } } }
I want to restrict mine to just the section’s entry list page.
@Makenosound: The Publish Filtering ext was the right extension to check out. Thank you! My extension is now working correctly.
Well, it still shows up on indexes that don’t use my custom field.
Is there any way to have it only embed the scripts if the custom field is being displayed in the column view?
Thanks for the help. :-)
public function initaliseAdminPageHead($context) { $page = $context['parent']->Page; if ($page instanceof ContentPublish and $page->_context['page'] == 'index') { $page->addScriptToHead(URL . '/extensions/color_chooser_field/assets/jquery.js', 50); $page->addScriptToHead(URL . '/extensions/color_chooser_field/assets/color-list.js', 51); } }
I think in my Order Entries field I perform an additional check to see whether the current section index view contains an Order Entry field. But I’m tired, and might be wrong!
Create an account or sign in to comment.
With my extension, I need to embed some js in the head of the admin area. I couldn’t figure out how to do it without being really redundant. Does anyone have some quick pointers on how to do this.
What I have is this in the admin area:
Individual entry pages
Section entry list page
My field.php function looks like this:
My extension.driver.php function looks like this:
My problem is that the extension.driver.php function adds the links to every page in the admin area. I need it to only embed where needed: just on the Section entry list page. I haven’t found another extension that does this, so I’m a little lost.