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

    This is a complete newbie question..

    I would like to show the date at the top of my website.

    The day, month and year are all in different colours so I have tried setting up 3 basic snippets and calling them inside my styled span tags.

    here is the basic snippet code for the day

    <?php
    return date("jS")


    month

    <?php
    return date("F")


    year

    <?php
    return date("Y")


    I thought you could put basic php code as a snippet and just call it by [[day]] [[month]] [[year]] but it is throwing out

    Parse error: syntax error, unexpected ’}’ in F:\Windows Server\xampp\htdocs\wdn-new\core\cache\elements\modsnippet\3.include.cache.php on line 8

    (the snippets are named day, month, year)

    Also when I save the snippet, modx removes the php end tag..

    Does anyone have any ideas? Have I got this completely wrong?

    Kindest regards

    Danny
      • 6504
      • 23 Posts
      Sorry, after reading it back I realised that I forgot to state that it is revo.

      Thanks
        • 28626
        • 87 Posts
        That should work well but don’t forget to put ;

        <?php
        return date("jS");


        PHP doesn’t require the closing tag (it is assumed when the file ends). Not specifying the closing ?> helps prevent accidents like additional whitespace which will cause session initialization to fail ("headers already sent").

        You could also combine it into 1 snippet

        <?php
        return date("jS")."$Separator".date("F")."$Separator".date("Y");


        Then use
        [[date? &Separator=`/`]]
        in your page with whatever separator you like.

        BTW open the file you want to put the snippet in, then switch to the elements tab and just drag and drop the snippet into your page

        Or to push it a bit further:

        <?php
        return "<span class='$colorDay'>".date("jS")."</span>".$Separator."<span class='$colorMonth'>".date("F")."</span>".$Separator."<span class='$colorYear'>".date("Y")."</span>";
        


        Then use this snippet:

        [[date? &Separator=`-` &colorDay=`color_day` &colorMonth=`color_month` &colorYear=`color_year`]]


        What’s left is to setup a style for your colorclasses in your stylesheet.

        .color_day{
        color:#FF0000;
        }


        ...etc

        Or if you’d rather set the colors directly:

        <?php
        return "<span style='color:$colorDay'>".date("jS")."</span>".$Separator."<span style='color:$colorMonth'>".date("F")."</span>".$Separator."<span style='color:$colorYear'>".date("Y")."</span>";
        

        and use this

        [[date? &Separator=`-` &colorDay=`red` &colorMonth=`blue` &colorYear=`green`]]

          • 6504
          • 23 Posts
          Ahhh, I did not put the trailing ;

          Thanks for your reply,

          Danny
            • 28626
            • 87 Posts
            One thing about the closing tag, of course this is only in cases where there is only php code.
            When php code is mixed with html for example the closing tag needs to be used.