We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10691
    • 36 Posts
    I’v created the following plugin:

    $begrip = array( 
    	'Aikuchi' => 'Kleine tanto zonder tsuba.',
    	'Ashi' => 'Smalle kanaaltjes van zachter staal uitlopend van de ji tot de hamon.',
    	'Austeniet' => 'Structuur van staal die nodig is om het staal te kunnen harden',
    	'Bo\'hi' => 'Ook wel "hi" genoemd. Is een groeve aan de bovenkant van het blad.',
    	'Bokken' => '(Meestal houten) oefenzwaard',
    	'Boshi' => 'De zichtbare hardingslijn (hamon) op de kissaki. ',
    // This goes long way on with much more definitions, you get the idea	
    ); 
    
    $modx->documentOutput = preg_replace( 
        '/(?<=[>\s(?]|^)(' 
            . implode( 
                '|', 
                array_map( 
                    create_function( 
                        '$s', 
                        'return preg_quote($s, "/");' 
                    ), 
                    array_keys( 
                        $begrip 
                    ) 
                ) 
            ) 
            . ')(?=[\s.,<)?]|$)/ie', 
        '\'<dfn title="\' . htmlspecialchars(\$begrip[ucfirst(strtolower(\'$0\'))]) . \'">$0</dfn>\'', 
        $modx->documentOutput
    );
    Basically, this automatically finds words on pages from the keys of the $begrip array and adds <dfn>-tags with explenation (values of the array) in the title attribute. This is very handy for new people who don’t know all the terminology about swords (which my website is about). Now I only need this in the articles, not on my indexpage, contactpage, and categorypages. So what I need to know is how to exclude those pages from executing the plugin on. Now I probably could use an if-statement on the lower part of the code, but I don’t know which variable to test on. Could someone please help me?
      • 10691
      • 36 Posts
      Well, in the end I solved this myself. As I expected, the solution was an if-statement on the lower part of the code. I used:
      $docInfo = $modx->getDocument($modx->documentIdentifier,'id');
      $docid = $docInfo['id'];
      if ($docid != 1 && $docid != 3 && $docid !=  7 && $docid !=  8 && $docid != 17)
      (1, 3, 7, 8 and 17 are the pages I excluded).
        • 22303 MODX Staff
        • 10,725 Posts
        Quote from: Ger at Apr 02, 2009, 03:31 AM

        Well, in the end I solved this myself. As I expected, the solution was an if-statement on the lower part of the code. I used:
        $docInfo = $modx->getDocument($modx->documentIdentifier,'id');
        $docid = $docInfo['id'];
        if ($docid != 1 && $docid != 3 && $docid !=  7 && $docid !=  8 && $docid != 17)
        (1, 3, 7, 8 and 17 are the pages I excluded).
        No need to call getDocument()...why not at the top of the plugin simply say...
        if (!in_array($modx->documentIdentifier, array(1,3,7,8,17))) {
            // plugin logic here
        }

        You could even make the array of id’s be a comma-delimited string editable in the configuration of your plugin.
          • 10691
          • 36 Posts
          Well, since I’m not very familiair with MODx, I searched for some bits in other plugins/snippets. Your solution probably works too, but I wasn’t aware of the $modx->documentIdentifier. wink