We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14281
    • 120 Posts
    I have a chunk called "PageContent" that looks like this:
    <div id="article">
    	<div class="entry" id="entry[*id*]">
    		<h2>[*longtitle*]</h2>
    		<div class='subtitle'>[*subtitle*]</div>
    		<div class="date">[[FormatDate? &stamp=[*publishedby*] &format=`F j, Y`]]</div>
    		<div class="entryContent">
    			[[ContentParser]]
    		</div>
    	</div>
    </div>

    And a snippet called "FormatDate" that looks like this:
    $stamp = isset($stamp) ? $stamp : time();
    $format = isset($format) ? $format : 'F j, Y';
    echo $stamp;
    return date($format,$stamp);

    When I place the chunk in a template, I get this error on the front end:
    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « PHP Parse Error »
     
    PHP error debug
      Error: 	date() expects parameter 2 to be long, string given	 
      Error type/ Nr.: 	Warning - 2	 
      File: 	/home/.jazzmen/jlivingston/lab.tiltedsymmetry.com/manager/includes/document.parser.class.inc.php(705) : eval()'d code	 
      Line: 	4	 
     
    Parser timing
      MySQL: 	0.1097 s s	(18 Requests)
      PHP: 	0.4174 s s	 
      Total: 	0.5271 s s


    What is the rendering order for MODx tags? If I call the snippet directly from the template, it works fine. And if I simply place the MODx tag "[*publishedby*]" in the chunk without trying to pass it to a snippet, it renders fine. But when the tag passes from the chunk to the snippet, it does so pre-rendered, so that my FormatDate snippet does not receive and actual timestamp.

    EDIT: Oh, and if anyone wonders why I’m passing the "publishedby" parameter as a timestamp, it’s because that is currently what it is being used for in the database. It appears that "publishedby" and "publishedon" have somehow switched roles, because the "publishedon" field appears to contain user id’s.
    • Put a debugging statement in your snippet to see exactly what is getting passed:
      echo gettype($stamp) . ' - ' . $stamp;

      http://il.php.net/manual/en/function.gettype.php

      If it is the UNIX timestamp that you expect, it may be being passed as a string and needs to be converted or cast to a long before getting fed to the date function.

      http://il.php.net/manual/en/language.types.type-juggling.php#language.types.typecasting
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 14281
        • 120 Posts
        I thought about that, but I didn’t even try to cast the string for three reasons:

        • I know that PHP is really good about forgiving incorrect types
        • This works when sending the stamp to the snippet from the template, and I’m pretty sure it’s being sent as a string then, too, since I’m placing it in either ’quotes’ or `back ticks`.
        • I made the snippet echo out the value of the stamp, and the result was "[*publishedby*]", instead of the actual value of the rendered tag, which indicated to me that the chunk sent the MODx tag prerendered.

        I know that this who issue of rendering order can get kind of confusing, so please let me know if I’m drawing any invalid conclusions here. I’ll also try to cast the string if you still think it will help.

        Thanks for the response, Susan.