We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I’m not sure about this one, it’s kind of a wacky idea, but it might be nice to have a tag with no inital element for use with filters where the element is ignored.

    In a tag like this:
    [[$ChunkName:isloggedin:is=`1`:then=`[[$LoggedInChunk]]`:else=`[[$NotLoggedInChunk]]`]]

    $ChunkName is never used but is still processed.

    I was thinking of something like this:
    [[NoElement:isloggedin:is=`1`:then=`[[$LoggedInChunk]]`:else=`[[$NotLoggedInChunk]]`]]
    [[NoElement:userinfo=`email`]]

    or
    [[-:isloggedin:is=`1`:then=`[[$LoggedInChunk]]`:else=`[[$NotLoggedInChunk]]`]]
    [[-:userinfo=`email`]]

    If a token would work better.

    The parser could just recognize the "-" token or "NoElement" and short-circuit the processing (maybe returning something arbitrary like "x" or an empty string if that wouldn’t cause trouble).

    It might also be useful to have some kind of elementless tag that recognized string literals for use with other filters:
    [[`Ham & Eggs`:htmlent]]

    or
    [[-'Ham & Eggs':htmlent]]


    Hopefully, this could also work in tags with filters used as snippet parameters.
    [[SnippetName? &user=`[[-:userinfo:username]]`]]
      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
      • 22303 MODX Staff
      • 10,725 Posts
      IMO, this defeats the modularity of the parser. Having each element class have an implementation that is only loaded on demand keeps the parsing code lean and efficient. Having literals or non-element implementations would add overhead to every request, and every parsing cycle within that request, and to be honest, I’m looking harder for ways to improve efficiency and simplify the code. And why not just use the If snippet for conditionals (I will never recommend using filters as conditionals) or write your own quick conditional snippet for those cases?
        • 3749
        • 24,544 Posts
        Quote from: OpenGeek at Jul 14, 2009, 12:32 AM

        IMO, this defeats the modularity of the parser. Having each element class have an implementation that is only loaded on demand keeps the parsing code lean and efficient. Having literals or non-element implementations would add overhead to every request, and every parsing cycle within that request, and to be honest, I’m looking harder for ways to improve efficiency and simplify the code. And why not just use the If snippet for conditionals (I will never recommend using filters as conditionals) or write your own quick conditional snippet for those cases?

        That all makes sense, and I’d certainly use a snippet myself. I was thinking of PHP illiterates but it looks like the cost would outweigh the benefits.

        I guess that a user could create a dummy system setting to be used in those tags, that should process fairly fast.

        I’m not sure what you mean by "the if snippet." Have I missed something?
          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
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: BobRay at Jul 14, 2009, 01:20 AM

          I’m not sure what you mean by "the if snippet." Have I missed something?
          Sorry, I thought I had published it for the team previously; my mistake. But it’s basically just a simple script I call "If". Here it is for now; I’ll put it in the Extras repo later today...
          <?php
          /* simple if (conditional) snippet */
          $output = '';
          $operator = !empty($operator) ? $operator : '';
          $operand = !isset($operand) ? '' : $operand;
          if (isset($subject)) {
              if (!empty($operator)) {
                  switch ($operator) {
                      case '!=':
                      case 'NEQ':
                      case 'neq':
                      case 'ISNOT':
                      case 'isnot':
                      case 'ISNT':
                      case 'isnt':
                          $output = (($subject != $operand) ? $then : (isset($else) ? $else : ''));
                          break;
                      case '<':
                      case 'LT':
                      case 'lt':
                          $output = (($subject < $operand) ? $then : (isset($else) ? $else : ''));
                          break;
                      case '>':
                      case 'GT':
                      case 'gt':
                          $output = (($subject > $operand) ? $then : (isset($else) ? $else : ''));
                          break;
                      case '<=':
                      case 'LTE':
                      case 'lte':
                          $output = (($subject < $operand) ? $then : (isset($else) ? $else : ''));
                          break;
                      case '>=':
                      case 'GTE':
                      case 'gte':
                          $output = (($subject > $operand) ? $then : (isset($else) ? $else : ''));
                          break;
                      case 'empty':
                      case 'EMPTY':
                          $output = (empty($subject) ? $then : (isset($else) ? $else : ''));
                          break;
                      case '!empty':
                      case '!EMPTY':
                      case 'notempty':
                      case 'NOTEMPTY':
                          $output = (!empty($subject) ? $then : (isset($else) ? $else : ''));
                          break;
                      default:
                          $output = (($subject == $operand) ? $then : (isset($else) ? $else : ''));
                          break;
                  }
              }
          }
          return $output;
          ?>
            • 33337
            • 3,975 Posts
            Jason, have u put this in the Repo yet? tongue
              Zaigham R - MODX Professional | Skype | Email | Twitter

              Digging the interwebs for #MODX gems and bringing it to you. modx.link
              • 22303 MODX Staff
              • 10,725 Posts
              Quote from: zi at Jul 17, 2009, 06:09 AM

              Jason, have u put this in the Repo yet? tongue
              I will try to get it in there soon.
                • 3749
                • 24,544 Posts
                One more comment on elementless tags: In PHX, adding the PHX: prefix allows tags with no element like this:
                [+phx:userinfo=`username`+]

                People may have trouble translating these for Revo (unless I’m missing something).
                  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
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: BobRay at Jul 19, 2009, 02:11 AM

                  One more comment on elementless tags: In PHX, adding the PHX: prefix allows tags with no element like this:
                  [+phx:userinfo=`username`+]

                  People may have trouble translating these for Revo (unless I’m missing something).
                  They can create a ’phx’ snippet that does nothing if they need this I guess, but I don’t see the point of this and never have. This kind of stuff should be a snippet anyway; not exactly a modifier IMO.