We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21800
    • 174 Posts
    Hi,
    I want to show a date (Starttime, used for ditto calls) gathered via tv in a ditto content output.
    So I created a snipped like this in many variants

    <?php
    header(’Content-Type: text/html; charset=UTF-8’);
    setlocale(LC_ALL, ’de_DE@euro’, ’de_DE’, ’deu_deu’);
    $dateSource = isset($dateSource) ? $dateSource : "StartTime";
    return iconv(’ISO-8859-1’, ’UTF-8’, strftime("%d. %B. %Y | %H:%m", $dateSource));
    ?>
    mostly I get an output like this

    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « PHP Parse Error »

    PHP error debug
    Error: strftime() expects parameter 2 to be long, string given
    Error type/ Nr.: Warning - 2
    File: /srv/www/web/html/a/manager/includes/document.parser.class.inc.php(769) : eval()’d code

    some help would be appreciated
      • 7231
      • 4,205 Posts
      $dateSource = isset($dateSource) ? $dateSource : "StartTime";
      What is the dateSource and what is StartTime?

      I am guessing that this is not a valid parameter for strftime() due to the error message stating that the second parameter is not good.

      Error: strftime() expects parameter 2 to be long, string given
        [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]
        • 21800
        • 174 Posts
        StartTime is a tv I build for event management with Ditto.
        It’s the kind of date / unixtime tv, that allows for Starttime input while editing and sorting … while ditto displays (in the later case it works fine).
        dateSource I took as lokal variable to handle that.
          • 7231
          • 4,205 Posts
          I am thinking that the dateSource is not getting set.

          You need to get the value from the template variable either by using the getTemplateVarOutput api function
          $dateSource = $modx -> getTemplateVarOutput( "StartTime" );


          Or by including an input parameter to the snippet call:
          [!SnippetName? &dateSource=`StartTime`!]


          If this is a single purpose snippet I would hard code using the getTemplateVarOutput.

          However you do not need to format the date to use it with Ditto, set the dateSource, and dateFormat parameters and use the [+date+] placeholder.

          Here are some docs: http://ditto.modxcms.com/files/snippet-ditto-php.html#dateSource
            [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]
            • 18397
            • 3,250 Posts
            A better solution would be to create an extender which sets a placeholder you can use in the Ditto template. Take a look at the example extender for a how to.
              • 21800
              • 174 Posts
              Yes, a very elegant solution (regretted more than one time that I’m not fit enough for coding that), would need a more nearby example.
                • 21800
                • 174 Posts
                @dev_cw
                thanx for your time,

                your "$dateSource = $modx -> getTemplateVarOutput( "StartTime" );" proposal only results in "01. Januar. 1970 | 01:01"

                I only want to output the values of "StartTime" and "EndTime" as human readable in the content of the aproppriate content (as placeholder).

                i. e. if input of StatrtTime tv is "24. 4. 08" the date also appears in some chunk or snippet, that I can place in a template.

                <?php
                header(’Content-Type: text/html; charset=UTF-8’);
                setlocale(LC_ALL, ’de_DE@euro’, ’de_DE’, ’deu_deu’);

                /*$dSource = isset($dSource) ? $dSource : "StartTime"; */

                $dSource = $modx -> getTemplateVarOutput( "StartTime" );
                return iconv(’ISO-8859-1’, ’UTF-8’, strftime("%d. %B. %Y | %H:%m", $dSource));
                ?>
                doesn’t work
                  • 6726
                  • 7,075 Posts
                  And what about using the PHx dateformat filter (only used it with createdon, editedon and pub_date but might work for date tvs...) ?
                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l&#39;outil id
                    • 21800
                    • 174 Posts
                    @davidm
                    ??
                      • 7231
                      • 4,205 Posts
                      You can use PHx in your Ditto template chunks to format data. You can use the dateFormat function to format the date with PHx:
                      http://wiki.modxcms.com/index.php/PHx#date.28.3D.60dateformat.60.29

                      You need to set &phx=`1` in your ditto call to activate phx.
                      http://ditto.modxcms.com/files/snippet-ditto-php.html#phx
                        [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]