Return to Snippet

Revision: 37519
at December 11, 2010 07:14 by audiopleb


Initial Code
<?php

function set_sections()
    {
        // Remove the tab. This is lame.
        $script = '
            $("#'. $this->id .'.accessory").remove();
            $("#accessoryTabs").find("a.'. $this->id .'").parent("li").remove();
        ';
        
// Only show this on 1 page of the CP
        if($this->EE->input->get('C') == 'members' AND $this->EE->input->get('M') == 'view_all_members')
        {
            $script .= '
                $("#mainContent").prepend(\'
                    <div class="rightNav"> 
                        <div style="float: left; width: 100%;"> 
                                <span class="button"><a title="Export Members" class="submit" href="'.BASE.AMP.'C=addons_accessories'.AMP.'M=process_request'.AMP.'accessory=member_export'.AMP.'method=process_export">Export Members</a></span> 
                            </div> 
                        <div class="clear_left">
                    </div>\')';
        }
        
        // Output JS, and remove extra white space and line breaks
        $this->EE->javascript->output('$(function(){'. preg_replace("/\s+/", " ", $script) .'});');
        $this->EE->javascript->compile();
    }



/*
OR 

In the install of your Accessory/Extension, update it's controller field, 
so it only shows in that controller, then the hide tab script above never runs unless needed, 
and your hidden tab does not flash.
*/

$this->EE->db->where('class', 'My_cool_acc');
            $this->EE->db->update('accessories', array('controllers' => 'admin_content'));

Initial URL
http://forrst.com/posts/Show_Accessories_only_on_pages_they_need_to_be_use-BJ6

Initial Description

                                

Initial Title
ExpressionEngine Accessories only on certain pages

Initial Tags
javascript, php, jquery

Initial Language
PHP