DEV Community

Juan Fernandes
Juan Fernandes

Posted on • Originally published at juanfernandes.uk on

Automatic copyright year in Perch CMS

One of the things I still get asked to do a lot by clients, ones that don't have a site that is managed by a CMS - is to update their copyright year on the footer.

Now, this is fairly easy to do using PHP on its own, just using this line of code:

    <?php echo date("Y"); ?>

Enter fullscreen mode Exit fullscreen mode

But, you if allow your CMS users to edit the copyright text, then you can't use PHP in a Perch HTML template.

After reading this article, Passing Variables Into Templates, I created this code snippet that sets a variable with the current year and then I pass this variable to the Perch template.

    <?php
        $curYear = date('Y');
        PerchSystem::set_var('curyear',$curYear);
        perch_content_custom('Footer', array(
            'template'=>'footer.html'
        ));
    ?>

Enter fullscreen mode Exit fullscreen mode

This is the Perch template I use to add the copyright text and year.

    <p class="copyright">©2015 - <perch:content id="curyear" /> <perch:content
    type="text" id="footer-copyright" label="Copyright Text" required="true" /></p>

Enter fullscreen mode Exit fullscreen mode

This may be a bit over the top, I could simply just added the PHP code in the footer template and not allow the user change the copyright text, but my copyright statement is part of a bigger template that needs to be CMS managed.

I hope you found this tip useful. Let me know if you see any way I could improve this code.

How are you setting the copyright year?

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →