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

    How can I switch template (chunk defined in &tpl to show listing) based on a TV value.

    To explain better....My template outputs...
    1. Original Price
    2. Your price
    3. Savings


    But, sometimes an offer is run for a particular product, at that time the template needs to output
    1. Original Price
    2. Regular Price (is the same as Your Price from above)
    3. Offer Price
    for that partcular product.


    Therefore if the Offer Price TV has a value, then use the second template else use the first template.

    How can this be accomplished?

    best regards,

    Raavi
      • 34162
      • 1 Posts
      I would try to replace the chunk in the template with a snippet.
      That snippet simply gets the value of the Offer Price TV, and when it is set, it returns chunk2, otherwise chunk1.
      (I’m assuming here that chunks may contain TVs, if that is wrong, then the whole output should be created by the snippet so that no chunks are needed at all.)
        • 24278
        • 165 Posts
        Does ditto read the $tpl every time it processes a resourse?

        Because my TV is available for each document and when I try and read the value of the TV in the chunk specified for the $tpl, It returns the ID and value for the Listing Page which makes the call to ditto and not the document TV values.

        I hope I have been able to explain myself clearly.

        best regards,

        Raavi
          • 18397
          • 3,250 Posts
          No, Ditto only parses the chunk once. What I would reccomend doing is creating a simple snippet in the chunk that you pass [+tvofferValue+] to and if it exists, the snippet returns the formatted value. If it does not exist, the snippet returns nothing.
            • 21778
            • 223 Posts
            I’m not so stiff in php yet, but im trying to learn...

            If someone have time to write a quick example of this snippet?

            Meanwhile i shall do basic php tutorials and get stronger!! cool

            Edit: How do you get ditto to use a snippet instead of chunk for the &tpl= ?

            thanks
              • 4172
              • 5,888 Posts
              just put your snippetcall in your ditto-chunk.
              Thats it.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 21778
                • 223 Posts
                Quote from: Bruno17 at Nov 18, 2009, 05:07 AM

                just put your snippetcall in your ditto-chunk.
                Thats it.

                doh, of course. Thanks mate.

                So... something like this eh

                [!Ditto? &tpl=`Choose_chunk` !]

                CHUNK: Choose_chunk
                CONTAINS: [!Choose_Chunk!]

                SNIPPET: [!Choose_Chunk!]
                CONTAINS:
                If resource TV = old then get Chunk1
                If resource TV = new then get Chunk2

                My TV uses radio options.
                input is: old||new

                If anyone could help me write the snippet ill appreciate it greatly Smiley
                  • 4971
                  • 964 Posts
                  Ditto supports PHx so, you could use
                  the if statement with PHx...
                    Website: www.mercologia.com
                    MODX Revo Tutorials:  www.modxperience.com

                    MODX Professional Partner
                    • 4172
                    • 5,888 Posts
                    CHUNK: Choose_chunk
                    CONTAINS: [[Choose_Chunk? &name=`[+chunktv+]`]]

                    if you name them chunknew,chunkold

                    SNIPPET: [!Choose_Chunk!]
                    CONTAINS:
                    return ’{{chunk’.$name.’}}’;

                    or would this work? May be not because the order of parsing:

                    {{chunk[+chunktv+]}}
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!