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

    I have a copyright notice at the bottom of my pages. It outputs something that looks like this:

    Copyright © 2010 Link to my homepage

    The code for this is as follows

    <h4>Copyright © <?php echo date('Y'); ?> <a href="http://www.#.com/" title="Link Title">Link to my homepage</a></h4>


    I have this line pasted into the footer div in the default modx template. I have used this line many times on non modx sites I hand coded with no problems. It returns the current year. However, in modx site, the php does nothing. The page validates. If I look at the source code, I see the php there, not the year.

    What do I need to do differently? I do not want to have to update the year by hand on every site I manage. If I have to make this a snippet call, how do I make this return the year as a value and output it to the template? I’m not very good at writing my own php from scratch.

    Thanks,
    -Dan
      • 16702 ☆ A M B ☆
      • 536 Posts
      make new snippet with name year, and paste this code:

      <?php
      $output = date(Y);
      return $output;
      ?>


      and then back to template and use:

      [[year]]


      regards
        palma non sine pulvere
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Templates, chunks and document content cannot have PHP code. Use snippets, as Kristalin said.
          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
          • 6488
          • 23 Posts
          Ok. That works awesome. Thanks.

          -Dan