We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37131
    • 111 Posts
    In Articles, there is fragment of Chunk: sample.ArticleRowTpl as below:
        <div class="entry">
    	    <p id="blabla">[[+introtext:default=`
    [[+content:ellipsis=`400`]]`]]</p>
        </div>
        <p class="postmeta">
    

    and it generates this html:
    <div class="entry">
    	    <p id="blabla">
    </p><p><img width="261" height="401" alt="Nowe opakowanie Herbatki" src="images/news/2011/thermojetics-new.jpg" style="float: left;">Herbalife unowocześnia wygląd i ujednolica opakowania na całym świecie. W związku z tym Polska otrzymuje Herbatkę Rozpuszczalną w nowych, ładnych opakowaniach nawiązujących w stylu do znanych już m.in. z koktaili. Nowe jest tylko opakowanie, środek zawiera tą samą dopr…</p>
        </div>


    Can someone help me understand how it is possible that P tag with id `blabla` is empty and content of post if outside of it in the next paragraph. huh
      ---
      Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. Martin Golding
      • 3749
      • 24,544 Posts
      What happens if you do this:

         <div class="entry">
              <p id="blabla">[[+introtext:default=`
      [[+content:striptags:ellipsis=`400`]]` ]]</p>
          </div>
          <p class="postmeta">


      Ellipisis by itself is unreliable with HTML code because tags may not be closed.

      You can also do this to cut things off at a word boundary:

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



      <?php
      /* WholeWords snippet */
       
      $pos = strrpos($input, ' ');
      return substr($input, 0, $pos);


      Even with all that, it may not work the way you're using it because of the parsing order. You may need to use a custom snippet, which would look something like this (untested), which would be faster anyway:


      <div class="entry">
              <p id="blabla">[[+introtext:WholeWords`]]</p>
          </div>
          <p class="postmeta">



      <?php
      /* WholeWords snippet */
       if (! empty($input)) {
         return $input;
      } else {
         $input = $modx->resource->getContent();
         $input = $modx->stripTags($input);
         $input = substr($input,0,400);
         
         $pos = strrpos($input, ' ');
         return substr($input, 0, $pos);
      }


      If you want to preserve the tags in the content, it gets significantly more complicated.


      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html
        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
        • 37131
        • 111 Posts
        Thank s God some pro face dropped in my thread smiley Thanks for replying!
        I understand what you mean. I still don't get one small thing here.
        I was trying to ged rid if empty P paragraph - the one with id 'blabla'. Looking at Chunk's code (it's original from Articles, I've just added blabla id) - I expect that post's content should go inside of 'blabla' Paragraph. But it isn't. It looks like
        [[+introtext:default=`
        [[+content:ellipsis=`400`]]`]]

        makes
        </p><p><img width="261" height="401" alt="Nowe opakowanie Herbatki" src="images/news/2011/thermojetics-new.jpg" style="float: left;">Herbalife unowocze�nia wygl�d i ujednolica opakowania na ca�ym �wiecie. W zwi�zku z tym Polska otrzymuje Herbatk� Rozpuszczaln� w nowych, �adnych opakowaniach nawi�zuj�cych w stylu do znanych już m.in. z koktaili. Nowe jest tylko opakowanie, �rodek zawiera t� sam� dopr�

        But it would be strange (starts with closing P and leaving next P open ...
        Original content of post is (copied from database table):
        <p><img style="float: left;" src="images/news/2011/thermojetics-new.jpg" alt="Nowe opakowanie Herbatki" width="261" height="401" />Herbalife unowocześnia wygląd i ujednolica opakowania na całym świecie.......</p>
        [ed. note: khyrlik last edited this post 14 years, 7 months ago.]
          ---
          Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. Martin Golding
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          If you're using TinyMCE it's probably "helpfully" inserting its own p tags in your content.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 37131
            • 111 Posts
            That was first thing I've checked, apparently it was adding p tags, but I removed them before starting this thread.
              ---
              Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. Martin Golding
              • 25201
              • 94 Posts

              I've tried the :WholeWords modifier, but it doesn't work and I don't see it in the documentation.. Any idea?

              Thx
                • 3749
                • 24,544 Posts
                It's a custom modifier, you need to create the snippet.

                The first example above is really the WholeWords modifier. The second example should be called something else.
                  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
                  • 25201
                  • 94 Posts
                  Sand in my eyes this morning, thanks. Added the ellipsis on the return string.
                    • 37131
                    • 111 Posts
                    I know that english is not my first language and I may not explain this clear enough (or I'm just PITA), but this behaviour annoys me. More simple example:
                    This fragment of chunk:
                    <div class="entry">
                    	    [[+introtext:default=`nointro-start [[+content:ellipsis=`400`]] nointroend`]]
                        </div>
                        <p class="postmeta">
                    ...

                    generates this code:
                    <div class="entry">
                    nointro-start 
                    <p>
                    Nowe jest tylko opakowanie, środek zawiera tą samą dopr… nointroend
                    </p>
                    </div>
                    <p class="postmeta">...

                    Who put this last /P there ?
                    PS. Something is wrong here (in Articles code od MODx), cause when I remove P tags enclosing call to introtext (like above), whole page brokes a bit - Latest Articles is not displayed on the right side, but under 'Last' link on page navigation. [ed. note: khyrlik last edited this post 14 years, 7 months ago.]
                      ---
                      Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. Martin Golding
                      • 25663 MODX Staff
                      • 12,272 Posts
                      Your call above looks to be inserting the default portion when there's no content in introtext. If so, it seems to behave as I would expect. Do you have content in the introtext?

                      (The closing paragraph tag may be inserted by the ellipsis output modifier … not sure as I've always used a slightly different summarizing snippet that tries to preserve tags and close things on purpose.)
                        Ryan Thrash, MODX Co-Founder
                        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me