Jump to content

Ability to alter links?


Recommended Posts

I have a situation where I have links to a bunch of forms on my site. Every year the links to the forms change slightly, adding the current year to the end. So it is something like http://www/somewhere.com/form1/2017. Next year it will be the same thing but with 2018 in the URL.

I was hoping HannaCode could help me out here by letting me create a snippet that would read the year from a settings page and insert that at the end of any links I specify. So in the CKEditor I create a link, add [[cyr]] (my HannaCode snippet that pulls back the year from the settings page and I verified that it is indeed working properly) to the end and instead of pulling in the year it is just encoding the [[cyr]] into the URL. I was expecting


 and I'm getting



Is HannaCode not able to work with raw HTML this way? Is there some other way to do what I'm trying to accomplish? I really don't want to go around the site updating 100 links when a new year comes around.

All the links are to forms on an external site in case that helps...


Link to comment
Share on other sites

Here's a micromodule for you: Save this in site/modules/TextformatterCurrentYear/TextformatterCurrentYear.module. Then refresh modules and install it. Once it's installed, add it to your field's textformatter list. It will replace all instances of `curryear` with the current year (4 digits `2017` for example). You can set it once and forget it

<?php namespace ProcessWire;

class TextformatterCurrentYear extends Textformatter {
    public static function getModuleInfo()
        return [
            'title'   => 'Current Year Replacer',
            'version' => '1.0.0',
            'summary' => 'Replaces `curryear` with current year',

    public function format(&$str)
        $str = str_replace('curryear', date('Y'), $str);


  • Like 1
Link to comment
Share on other sites

You can't enter a Hanna tag via the "Insert link" modal because the href gets entity encoded.

But you can use a Hanna tag for generating the whole link:

// Hanna tag "year_link", with attributes "url" and "link_text"
$year = $pages->get('/settings/')->year;
$href = $url . $year;
$text = $link_text ?: $href;
echo "<a href='$href'>$text</a>";


Please fill out this [[year_link url="http://www.somewhere.com/form1/" link_text="form"]]


  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...