We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36786 ☆ A M B ☆
    • 209 Posts
    Is there a way to call the character count of a placeholder and use that in a conditional output modifier?

    As an example: If the content of an article/resource is greater than a certain number of characters, it won't just add ellipses, but also show a link to the full article? This is what I have now, but I can't figure out how to use character count for conditional statements.

    [[+content:ellipsis=`300`]]

    Is this possible?

    Thanks guys!

    This question has been answered by markh. See the first response.

      Ben Morrison
      Hacking templates to pieces since 2003
      • 31946
      • 116 Posts
      Hi maroonlover,
      you could write a snippet that does this stuff for you.
      Simple Example:
      <?php
      $output = $input;
      $nChars = 200;
      if(strlen($input) > $nChars){
       $output = substr($input,0,$nChars);
       $output .= '... <a href="'.$modx->makeUrl($articleId).'">read</a>';
      }
      return $output;

      Then call your snippet like this:
      [[snippet? &input=`[[+content]]` &articleId=`[[+id]]`]]
      • discuss.answer
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        Could do that with output modifiers if you want to, tho a snippet would probably be more flexible:

        [[+content:len:gt=`200`:then=`<a href="[[~[[+id]]]]">Read more</a>`:else=`That's all folks!`]]
        
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 36786 ☆ A M B ☆
          • 209 Posts
          Thanks Mark! I misunderstood the documentation
            Ben Morrison
            Hacking templates to pieces since 2003