Grabbing current year

matthew.wren's Avatar

matthew.wren

09 Sep, 2015 05:53 PM

I'm familiar how to do this with Velocity but I'm not sure how to grab the current year using XSLT. I'm looking at update our footer content on our site so we no longer have to manually add the year.

  1. 1 Posted by Ryan Griffith on 09 Sep, 2015 06:47 PM

    Ryan Griffith's Avatar

    Hi Matthew,

    For simplicity, I would definitely recommend using Velocity if you can.

    If you need to use XSLT, do you have the formatting date XSLT by chance? If so, I believe you should be able to call the format-date template without a date parameter and provide a mask of yyyy. This should default to the current date and output the current year.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by matthew.wren on 10 Sep, 2015 07:40 PM

    matthew.wren's Avatar

    I went with your recommendation and created a velocity format that grabs the current year. Here's the final format:

    #set ($thisyear = $_DateTool.getYear()) 
    #set($copyright = $_XPathTool.selectSingleNode($contentRoot,"//copyright").value)
    
        <div id="footerCopyright">
                <!--//** BEGIN:  footerCopyright **//-->
                <div class="footerLogo">
                    <a href="http://www.scranton.edu/" target="_blank">
                        <img alt="The University of Scranton" height="41" src="/alumni/journal/global/images/footer/scranton-logo-small.gif" width="156"/>
                    </a>
                </div>
                    Copyright ${thisyear} $copyright
                <br/>
            </div>
    
  3. 3 Posted by Ryan Griffith on 10 Sep, 2015 08:31 PM

    Ryan Griffith's Avatar

    Looks about right, Matthew. Additionally, you could use the Locator Tool to grab that copyright value, thus dropping the required Index Block.

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  4. Ryan Griffith closed this discussion on 10 Sep, 2015 08:31 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac