We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3109 ☆ A M B ☆
    • 894 Posts
    Ok so I made a new personal website which I am hosting as a secondary context on one of my sites and for some reason it is loading SyntaxHighlighter assets even though they are not referenced anywhere on my template.

    I use SyntaxHighlighter on the main site but not in this new context has anyone experienced anything like this before?

    Looking at the SyntaxHighlighter snippet it seems like it's injecting into all templates, this is starting to look like bug.

    Anyone have any idea how I can modify this snippet so it doesn't load only on the context it needs to be loaded in.

    Thanks.

    $brushes = empty($scriptProperties['brushes'])? 'JScript,Xml,Php,Css,Plain' : $scriptProperties['brushes'];
    
    $brushArray = explode(',', $brushes);
    
    $baseURL = $modx->getOption('sh.assets_url', null, $modx->getOption('assets_url') . 'components/syntaxhighlighter/');
    
    $modx->regClientStartupScript($baseURL . 'scripts/shCore.js');
    
    foreach($brushArray as $brush) {
        $modx->regClientStartupScript($baseURL . 'scripts/' . 'shBrush' . $brush . '.js');
    }
    
    $modx->regClientCss($baseURL . 'css/' . 'shCore.css' );
    $modx->regClientCss($baseURL . 'css/' . 'shThemeDefault.css' );
    $modx->regClientScript('<script type="text/javascript">
         SyntaxHighlighter.all();
    </script>');
    
    return '';
    
    
      Benjamin Marte
      Interactive Media Developer
      Follow Me on Twitter | Visit my site | Learn MODX
      • 3109 ☆ A M B ☆
      • 894 Posts
      UPDATE

      So I ended up making an if statement in the snippet so it only renders in the web context, this solved my issue for now but it seems like this extra needs to be modified to handle multiple contexts.

      Here is my modified SyntaxHighlighter snippet:

      $brushes = empty($scriptProperties['brushes'])? 'JScript,Xml,Php,Css,Plain' : $scriptProperties['brushes'];
      
      $brushArray = explode(',', $brushes);
      
      $baseURL = $modx->getOption('sh.assets_url', null, $modx->getOption('assets_url') . 'components/syntaxhighlighter/');
      
      $currentContext = $modx->context->key;
      
      if($currentContext == 'web'){
          $modx->regClientStartupScript($baseURL . 'scripts/shCore.js');
      
          foreach($brushArray as $brush) {
              $modx->regClientStartupScript($baseURL . 'scripts/' . 'shBrush' . $brush . '.js');
          }
      
          $modx->regClientCss($baseURL . 'css/' . 'shCore.css' );
          $modx->regClientCss($baseURL . 'css/' . 'shThemeDefault.css' );
          $modx->regClientScript('<script type="text/javascript">
               SyntaxHighlighter.all();
          </script>');
          
          return '';
      }
      
        Benjamin Marte
        Interactive Media Developer
        Follow Me on Twitter | Visit my site | Learn MODX
        • 3749
        • 24,544 Posts
        Ben, no snippet can execute unless it's called (iow, there's a tag for it in some page that's being processed or some other snippet is calling it with runSnippet()).

        Are you sure that the SyntaxHighlighter *plugin* is not enabled? That would run in all contexts.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 3109 ☆ A M B ☆
          • 894 Posts
          Bob the plugin is not disabled since I need it to run in the web context but not in the second context.

          Under System Events there's a checkmark in OnLoadWebDocument.

          If I understand you correctly, you are saying that I can enable disable this plugin per context?

          Again my template has no call to any SyntaxHighlighter snippets or anything I believe the regClientStartupScript is whats injecting it into all my templates regardless or not if I'm using SyntaxHighlighter in this instance of MODX.

          Thanks.
            Benjamin Marte
            Interactive Media Developer
            Follow Me on Twitter | Visit my site | Learn MODX
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I think there has been a miscommunication here. SyntaxHighlighter can be either a snippet or a plugin, not both. If you have the plugin enabled, it will run in all contexts. If you don't enable the plugin, you can use the snippet in templates or resources as needed.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 3109 ☆ A M B ☆
              • 894 Posts
              Susan thanks for the clarification so I was using it wrong I had the plugin enabled, I guess I have to go and edit all my templates now.


              Bobray my apologies for stating this was a bug it was just my stupidity of not knowing how to use your plugin properly.

              Thanks for the help guys. [ed. note: benmarte last edited this post 12 years, 4 months ago.]
                Benjamin Marte
                Interactive Media Developer
                Follow Me on Twitter | Visit my site | Learn MODX
                • 3749
                • 24,544 Posts
                No Sweat. Maybe the docs need clarification. smiley
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting