We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31088
    • 14 Posts
    Hello,
    This should work; I’m baffled that I can’t get it to work. Sure could use some guidance...

    I have a TV called showDate, using checkbox to set it to `1`, or not.
    In my Ditto template I have:
    [+showDate:is=`1`:then=`<small>[+date+]</small>`+]

    I’ve tried many things, including:
    [+phx:if=`[*showDate*]`:gt=`0`:then=`<small>[+date+]</small>

    And I’ve switched the * and + to various combinations, because sometimes I must admit the subtleties of Ditto can baffle me a bit.

    Is this even possible? because I can’t find any info on this which works for me...

    Thanks for any suggestions
      • 31088
      • 14 Posts
      Hi
      Well I’ve given up on doing it this way, I just can’t make it work.
      So now I’m just trying to load a different chunk depending on the value of ’showDate’.
      {{[+showDate+]}}

      showDate tv would just have either ’showDate.ch’ or ’hideDate.ch’ and those are little chunks with
      <h5 class="post-date">[+date+]</h5>
      or
      <br />


      But even this won’t work. Dates are going to be what makes me give up and start making everything in CodeIgniter, I swear. I’m too stupid for this, clearly. I’ve tried snippets, chunks, whatever. Using different templates for content items on different pages is not scalable, I hate doing it.
      I have even tried filtering ditto date results based on epoch (if(epoch) don’t show) tongue


      crap.
        • 22427
        • 793 Posts
        Have you defined your own TV [tt][*date*][/tt]?
        As far as I know there is no placeholder [tt][*date*][/tt] for documents.

        You may use [tt][*pub_date*][/tt] or [tt][*createdon*][/tt] or [tt][*editedon*][/tt].
        Within the Ditto template you always have to use [tt][+....+][/tt] instead of [tt][*....*][/tt].
        So try [tt][+showDate:is=`1`:then=`<small>[+createdon+]</small>`+][/tt]

        EDIT:
        Sorry, of cource you can use the placeholder [tt][+date+][/tt] in the Ditto template. (So you are right: "This should work.")
        Forgot to say: [tt][+createdon+][/tt] will give just the timestamp (number of seconds since 1970-01-01), so you have to modify it using a date format, for example [tt][+createdon:date=`%Y-%m-%d`+][/tt]
          • 22427
          • 793 Posts
          I played a bit around and met anew a wellknown trap with Ditto:
          It wants to have a placeholder or TV in its template, otherwise the output will be empty.
          The problem is: having the TV within a phx placeholder, that wouldn’t help. The TV has to occur outside of the phx construct.

          So I found confirmed that this would not work:
          [+phx:if=`[+showDate+]`:is=`1`:then=`[+date+]`+]<br/>
          
          because there the TV is only occuring within the phx placeholder.

          On the other hand, the following works like expected, because the TV is also present unmodified:
          [+showDate+][+phx:if=`[+showDate+]`:is=`1`:then=`[+date+]`+]<br/>


          Fortunately I found a trick to get rid of the unwanted output of [tt][+showDate+][/tt] at the beginning - we simply modify it to an empty string:
          [+showDate:len:gt=`0`:then=``+][+phx:if=`[+showDate+]`:is=`1`:then=`[+date+]`+]<br/>

          That does it! This is strange enough since now again the TV does not occur unmodified...

          Additional observation: Using the short version
          [+showDate:is=`1`:then=`[+date+]`+]<br/>
          
          instead of
          [+phx:if=`[+showDate+]`:is=`1`:then=`[+date+]`+]<br/>

          will never result in the wanted output.

          And a remark: Using [tt][*showDate*][/tt] would refer to the value of the TV for the document which contains the Ditto call - normally the one given in the [tt]&parents[/tt] parameter. That may have sense if you want to control an equal behaviour of all its child documents through just one value.
            • 16278
            • 928 Posts
            I think this is the purpose of the &hiddenFields parameter ("Allow Ditto to retrieve fields its template parser cannot handle such as nested placeholders and fields"). So you could try just adding &hiddenFields=`showDate` to your Ditto call.

            I’ve come across this problem before, but in forms, so I could add a hidden field to flush out the placeholder value. I’ve always wondered if this parameter would have the same effect, and a quick test seems to confirm it.
            laugh KP
              • 31088
              • 14 Posts
              @ottogal - Thank you so much, you have helped me solve this and several other nagging issues at once grin

              @kp52 - ’&hiddenFields’? that’s great, I’ll have to test it out; looks like something that will come in very handy, thank you very much.

              -g
                • 22427
                • 793 Posts
                purpose of the &hiddenFields parameter ("Allow Ditto to retrieve fields its template parser cannot handle such as nested placeholders and fields")
                Thank you, kp52, for this reminder: Once upon a time I knew that...