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

    First : Thanks for all your modx job, really impressive guys

    Now, after this ’I love you guys’ phasis, let’s go to the main subject : Template Logic cool

    Since we started working on Modx with a collegue of mine, we found that it missed a kind of TemplateLogic.

    Situation :
    "Imagine you have a template in which you want to display a picture (url defined in a TV:image). This image will be linked to a document (ID defined in another TV : doc).
    In term of presentation, if image url is not defined ... it will not be really pretty smiley. If there is no id, a link will be created to [~~] ... "

    The only way to avoid si ’dirty’ behaviour was to create a snippet to verify if ’image’ and ’doc’ were defined and then ad the chunk. If not, no display...

    This solution is interesting except that for each TV/parameter and/or condition (perhaps it won’t be empty but <19 or <>"bye", ...) you have to create a new snipet.
    Moreover, in our opinion, it is clearly not the snippets role to define the way HTML part will be displayed. We also don’t want to rely on Javascript ( :’( )

    To solve our disappointement smiley, we developped our TemplateLogic tongue
    It will be released soon as a plugin (our development was made modifiying Modx Parser so we cannot publish it as it is grin )

    Our idea :
    Add new ’tags’ to be parsed by Modx to decide or not to display part of HTML template.

    Syntax :

    [-if &condition=`true`-]
    test if
    [-endif-]

    [-if &condition=`[+author+]==13` -]
    HTML texts / chunk calls / snippet calls ...
    [-else-]
    HTML texts / chunk calls / snippet calls ...
    [-endif-]

    Syntax2 (under study) :
    {{chunkName? &type=`if` &condition=`[*id*]==12` }} to be really close to snippet call syntax ...

    I’ll come back later to publish our plugin in a documented Way grin but BTW, please feel free to give us your comments on this.
    (perhaps we missed some feature in Modx that can do what we were looking for ...)
      • 25663 MODX Staff
      • 12,272 Posts
      Great job. This is a perfect application for a plugin. Thanks for taking the initiative; I look forward to seeing the results! laugh
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 22815
        • 1,097 Posts
        This would be absolutely stunning. You ask if you’ve missed an existing feature.. well, there is a new parser in development that does many things and touches on this territory, but that shouldn’t particularly negate what you’re doing.

        I absolutely agree with the need to remove dirty behaviour. Other systems have a lot of <strong>[field that might not actually have any content]</strong>, which always annoys me.

        Being able to specify in a template a style to apply around a snippet but only have that html output if it’s needed is very exciting.

        I prefer the first syntax, given that it will wrap around HTML and snippets etc. A snippet call-type syntax is probably more confusing.

        Can you confirm that
        [-if &condition=`[+picture+]` -]
        would evaluate to true if the "picture" tv wasn’t empty?

        One note: I definitely recommend that you go through and verify that there are sufficient plugin points to convert your hacked parser into a plugin code ASAP. While MODx 0.9.5 is being completed there’s the opportunity for new ones to be added if there is a need for them.

        BTW, I particularly like that you have considered and explored the current methods and then decided to plug the gap in MODx’s page construction logic. This has to my favourite First Post *ever*.
          No, I don&#39;t know what OpenGeek&#39;s saying half the time either.
          MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
          Forum: Where to post threads about add-ons | Forum Rules
          Like MODx? donate (and/or share your resources)
          Like me? See my Amazon wishlist
          MODx "Most Promising CMS" - so appropriate!
          • 6726
          • 7,075 Posts
          This is amazing, I have to agree with Paul about the greatest first post ever, quite a striking way to enter the community grin

          Conditionnal testing is a key missing feature for me, especially since it means cleaner templates but also, less of them (and this means less maintenance, less potential errors...).

          I really look forward to test this plugin, the concept sure is great !
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l&#39;outil id
            • 17448
            • 2 Posts
            Hi,

            I discover Modx one month ago and I work with chapi456 who posted this topic. We develop a first version of TemplateLogic plugin. I test the ask of PaulGregory and can confirm the possibility of use TV, variable or placeholder in the condition clause wink.

            Quote from: PaulGregory at Oct 04, 2006, 10:16 AM

            Can you confirm that
            [-if &condition=`[+picture+]` -]
            would evaluate to true if the "picture" tv wasn’t empty?

            If the tv is empty, the test is false.

            For example you can use this syntax in document content, chunk or template like this :

            [-if &condition=`[*id*] == 10`-]
            {{callChunkOK}}
            [-else-]
            {{callChunkKo}}
            [-endif-]

            or

            [-if &condition=`[*myTV*]`-]
            [*myTV*]
            [-endif-]

            Me and chapi456 will come back tomorrow or on the next week to publish this plugin and allow you to test it smiley
              • 4195
              • 398 Posts
              Ok, cool looking forward to this one smiley

              I was toying with a similar solution which will be included in the upcoming PHx plugin version.

                Armand Pondman
                MODx Coding Team
                :: Jot :: PHx