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

    Is it possible to limit the number of characters when displaying a template variable?

    Cheers
      • 5532
      • 251 Posts
      Is this something PHx could be used for maybe?
        • 16702 ☆ A M B ☆
        • 536 Posts
        name: phx:character_limit

        <?php
        $output_truncated = substr($output, 0, $options);
        return $output_truncated;
        ?>


        usage: [+content:character_limit=`10`+]
          palma non sine pulvere
          • 5532
          • 251 Posts
          Thanks Kristalin,

          I’d just installed the PHx plugin and although I didn’t understand your PHP, when I added the following into my Ditto template, it worked a treat:
          <p>[+textBlock1:limit=`700`+]...</p>


          The only issue is that when ’OnParseDocument’ was ticked for the PHx plugin, the Ditto pagination stopped working. However, unticking ’OnParseDocument’ made the Ditto pagination work and the limiting of characters still occurred?

          Does anyone know why this is? Or is PHx built in to Modx these days as I noticed another modifier worked before I even installed PHx. The modifier was:
          [*createdon:date=`%B %d %G`*]


          Sorry if this is all simple, I have no PHP experience and just want to make sure that I’m not hacking things without understanding if I’m going to cause issues later on - everything is working great at the moment.

          Cheers
            • 16278
            • 928 Posts
            Ditto has its own copy of PHx functions, so you don’t need to install the full PHx plugin to use it in Ditto templates (but note, PHx won’t be available in the full pages linked to from the Ditto list unless you do install the full plugin).

            If you do install the PHx plugin, you have to change the cacheing arrangements for pagination to work. With no PHx plugin, you need the snippet to be called [!uncached!]. With the plugin active, you need to call the snippet [[cached]], and make the page "not cacheable" in the page settings tab.

            Several other key snippets include their own PHx libraries, e.g. Maxigallery and Jot, reducing the need to install the full plugin.
            smiley KP
              • 5532
              • 251 Posts
              Thank you, that explains a lot!
                • 37447
                • 6 Posts
                if you don't want tags like <img><h1><h2> etc... you can do :

                [+content:notags:limit=`300`+]


                For more information... visit my website

                http://manuales.todolovisto.com/limitar-la-salida-del-contenido-modx