{"id":2723,"date":"2011-02-14T21:11:46","date_gmt":"2011-02-14T15:41:46","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=2723"},"modified":"2022-01-12T19:01:59","modified_gmt":"2022-01-12T13:31:59","slug":"using-taglib-to-avoid-changes-due-to-change-in-urlmappings","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/using-taglib-to-avoid-changes-due-to-change-in-urlmappings\/","title":{"rendered":"Using TagLib to avoid changes due to change in URLMappings"},"content":{"rendered":"<p>Recently, I used Taglib to centralize the effect of URL mapping related changes of my grails application.<\/p>\n<p>[java]<br \/>\ndef userPageLink = {attrs, body -&gt;<\/p>\n<p>def user = User.read(attrs.id)<\/p>\n<p>out &lt;&lt; g.link(controller: &#8216;user&#8217;, action: &#8216;show&#8217;, params: [name: user.name]) {body()}<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>So wherever I need a link to user page, I can use this Taglib instead of g:link.<\/p>\n<p>[java]<br \/>\n&lt;hys:userPageLink id=&quot;${user.id}&quot;&gt;${user.name}&lt;\/hys:userPageLink&gt;<br \/>\n[\/java]<\/p>\n<p><strong>Advantage:<\/strong><\/p>\n<p><\/br>Whenever I change the URL Mappings, there is no need to update all the g:link in all my gsp files. I would just update my taglib to cater to new URL Mapping.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I used Taglib to centralize the effect of URL mapping related changes of my grails application. [java] def userPageLink = {attrs, body -&gt; def user = User.read(attrs.id) out &lt;&lt; g.link(controller: &#8216;user&#8217;, action: &#8216;show&#8217;, params: [name: user.name]) {body()} } [\/java] So wherever I need a link to user page, I can use this Taglib instead [&hellip;]<\/p>\n","protected":false},"author":26,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[7],"tags":[4840,213,32,50],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2723"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=2723"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2723\/revisions"}],"predecessor-version":[{"id":54612,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2723\/revisions\/54612"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=2723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=2723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=2723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}