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

    I would like to format date-based TVs like [*createdon*] to a readable form. From what I’ve read, it seems that a snippet might be called for. I tried this (and various variations with or without quotes around the TV call, putting a Unix timestamp there works fine):

    <?php
    $zeitstempel_zu_datum = "[*createdon*]";
    echo strftime("%d/%m/%y, %H:%M:%S", $zeitstempel_zu_datum);
    ?>


    which doesn’t work, but results in a parsing error.

    Is there a way to use a TV in a snippet like I tried or do I need to pull the create date from the database as in the AuthorTime snippet?
      • 10487 MODX Staff
      • 1,535 Posts
      You will need to use $modx->documentObject[’createdon’] instead of [*createdon*] when trying to access document properties within a snippet (ie. PHP) code.
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 28465
        • 29 Posts
        It works! Thanks a lot! laugh
          • 7231
          • 4,205 Posts
          Hello, I am trying to use a TV in a snippet but am failing. My objective is to specify a directory to be used in a file path, so I set up a TV with the directory location.

          $path = "assets/images/$modx->documentObject['my_folder']/";


          but I get a parse error and I can see that the TV is not being displayed. What am I doing wrong? huh


            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 27376
            • 576 Posts
            Quote from: dev_cw at Jun 21, 2007, 05:31 PM

            $path = "assets/images/$modx->documentObject['my_folder']/";


            Make your code like this:
            $path = 'assets/images/' . $modx->documentObject['my_folder'] . '/';