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

    Odd request. I'm looking to set a charset for certain templates and pages and it works fine if i set the front end charset to iso-8859-1 as it shows me the special characters (which is what my client wants to see). Problem is if I resave the page in the manager then the front end breaks because the manager and front end need to have the same charset. However the MODX system has multiple contexts and I want everything else to be UTF-8 except for on these certain pages.

    I've tried everything I can think of such as:
    - setting the charset in the meta tag
    - decarling the containing div element as a specific charset
    - using a snippet to set the content type
    - using javascript to encode/decode


    Not having much luck though. Any ideas?
      ■ email: [email protected] | ■ website: https://alienbuild.uk

      The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
      • 38783
      • 571 Posts
      Would using this to alter the char set for specific documents or templates help?
      Wondering if the time at which the charset is defined in the page might make a difference.
      https://docs.modx.com/revolution/2.x/developing-in-modx/basic-development/plugins/system-events/onwebpageprerender

        If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

        email: [email protected] | website: https://andytough.com
        • 3749
        • 24,544 Posts
        Could you just create a filter for the page content that would make the special characters visible without altering them in the DB?

        Which "special characters" are we talking about? The FixedPre extra might help.
          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
          • 17301
          • 932 Posts
          Thank you both.

          Good suggestion Andy i'll give that one a go shortly and report back!

          Bob - for special characters I mean characters that would traditionally need to be encoded if the charset was iso-8859-1. So for example typing this word:

          ¡Siesta!

          Should be rendered out like this:

          https://imgur.com/a/3fRMh

          If I could get this to display incorrectly like the image above then it would help my client able to debug characters in their pages before they go live onto a CMS that isn't MODX.



            ■ email: [email protected] | ■ website: https://alienbuild.uk

            The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
            • 3749
            • 24,544 Posts
            If, by some chance, you had a complete list of the characters, you could use a plugin that would render them in a way that made them stand out (e.g., wrapping them in span tags with a style the changed the font-size and/or color).

            Even without the list, you could find them in various ways:



            This looks promising (assuming that MODX is set for utf-8) as a plugin or snippet to use before export:

            https://sourceforge.net/projects/phputf8/files/

            require_once('libs/utf8/utf8.php');
            require_once('libs/utf8/utils/bad.php');
            require_once('libs/utf8/utils/validation.php');
            require_once('libs/utf8_to_ascii/utf8_to_ascii.php');
            
            if(!utf8_is_valid($str))
            {
              $str=utf8_bad_strip($str);
            }
            
            $str = utf8_to_ascii($str, '' );


            Also ... This finds and strips non-printable characters, but could be modified to make them more visible:

            $str = 'aAÂ';
            $str = preg_replace('/[[:^print:]]/', '', $str); // should be aA


            Something like this:

            $pattern = '/([[:^print:]])/';
            $replacement = '<span style="color:red; font-size:1.5 em">${1}</span>';
            
            $str = preg_replace($pattern, $replacement, $str);


            Another possible pattern for the above:

            $pattern = '/([^\x20-\x7E])/','', $str);
              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
              • 17301
              • 932 Posts
              Wow thank you, Bob that looks perfect. I'll give it a try shortly and report back.
                ■ email: [email protected] | ■ website: https://alienbuild.uk

                The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.