We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15001
    • 697 Posts
    Hi everyone,

    I tried using Geshi to highlight some PHP code but cannot make it work.

    In the [*content*] area of my page is this code. The 2 paths both seem correct to me.
    I also checked that geshi.php has execution rights. Is something wrong in code below ?

    <?php
    include_once('assets/snippets/geshi/geshi.php'); 
    $source = '$fichier= "modx_ressources/treasure_chest/treasurechest.francais.php"; include($fichier);';
    geshi_highlight($source, 'php', $path);
    ?>

    I know there is also some "Geshi plugin" for MODx but did not try it yet.

    Thanks for any help.
      • 33372
      • 1,611 Posts
      When you say that this code is in the content area of your page, do you mean as a snippet or just entered into the content field? PHP code in the document fields is not executed by MODx. You have to create a snippet and enter it into your page content or template.

      I’m not sure I understand what you’re trying to do exactly, since you generally need to return something as page output from snippet code (if the geshi_highlight function echos output, you may need to change it to store that to a variable and then return it at the end of your snippet).
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
        • 15001
        • 697 Posts
        Hi, code

        What I’m trying to do is using some php code named "geshi.php" to highlight some source code.

        What I pasted before is the code of a snippet named "Geshi". As you can see, the code itself call geshi.php who does the real syntax highlighting job.

        There was some error in my snippet call (I had forgotten the "?" after the snippet name.)

        Currently, I’m trying to parse some code in the xbasic/xblite language.
        There is available syntax definition file for qbasic and I choose to use it.

        The file is inserted but not highlighted yet.

        I’m wondering if this can be due to Geshi using the paranoid mode.
        Or should I encode the file ?

        Thanks for any help.

        The snippet call :
        [!Geshi? &src=`codes/thefile.x` &lang=`qbasic` !]

        And the snippet calling the syntax highlighter :
        <?php
        if (!isset($src)) {echo "Le code source n'a pas pu être chargé.";}
        if (!isset($lang)) {$lang='qbasic';}
        include_once('assets/snippets/geshi/geshi.php'); 
        $fichier = "include_once('".$src."');";
        geshi_highlight(eval($fichier), $lang, $path);
        ?>

        N.B. The qbasic.php syntax definitions file is in subfolder "geshi" relatively to the location of the geshi.php file.
          • 33372
          • 1,611 Posts
          Take another look at the second paragraph of my first reply. MODx snippets need to return output, and I can’t tell whether the geshi_highlight() function does that or not from the code that you posted. My guess is that it doesn’t, so even if the code is executing as expected you won’t see anything because you’re not displaying it.
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 15001
            • 697 Posts
            Thanks.

            The content of the file prints, the syntax is not highlighted. I wonder if the file is printed by
            eval($fichier)

            or by the geshi’s output.

            In fact, I would like to have something like :
            $source = eval($fichier);

            that store the source code before passing it as argument to the GeSHi highlighter.

            But how to include some content without printing it ?
              • 33372
              • 1,611 Posts
              When you say that the content of the file prints, are you sure that you’re not just missing the CSS styles that create the highlighting?
                "Things are not what they appear to be; nor are they otherwise." - Buddha

                "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options