{"id":558,"date":"2010-04-19T11:51:56","date_gmt":"2010-04-19T06:21:56","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=558"},"modified":"2016-12-19T15:29:12","modified_gmt":"2016-12-19T09:59:12","slug":"test-link","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/test-link\/","title":{"rendered":"Test Link"},"content":{"rendered":"<p><strong>(based on Tom\u00e1s Lin\u2019s truthlink)<\/strong><\/p>\n<p>This is useful when one requires link on certain condition.<br \/>\nInstead of first using condition tag and then tag for link these can be combined into one using taglib.<\/p>\n<pre lang=\"groovy\">\r\n<g:if test=${condition> \r\n    <g:link controller:'controllerName' action:'actionName'> \r\n\ttext \r\n    <\/g:link> \r\n<g:if>\r\n<\/pre>\n<p>or<\/p>\n<pre lang=\"groovy\">\r\n<g:if test=${condition}>   \r\n   <a href=\"#\" class=\"abc\" style=\"color:#90B8FF;\"> \r\n     Text \r\n   <\/a> \r\n<g:if>\r\n<\/pre>\n<p>Other way of doing this is by using taglib.<\/p>\n<pre lang=\"groovy\">\r\nclass AbcTagLib {\r\nnamespaces \"abc\";\r\n\r\n    def testLink = {attrs, body ->\r\n        String attributes = ''\r\n        if (attrs['test']) {\r\n            attrs.remove('test')\r\n           if (attrs.keySet().contains(\"action\") || attrs.keySet().contains(\"controller\")) {\r\n                out << g.link(attrs, body)\r\n            } else {\r\n                attributes = \"${attrs.collect {k, v -> \" $k=\\\"$v\\\"\" }.join('')}>\"\r\n                out << \"<a \" + attributes + body() + \"<\/a>\"\r\n            }\r\n\r\n        } else {\r\n            out << body()\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>Now since the Tag is created condition test and and link can be combined into one<\/p>\n<pre lang=\"groovy\">\r\n<abc:testLink test=\"${condition}\" controller:'controllerName' action:'actionName'>\r\ntext                                        \r\n<\/abc:testLink>\r\n<\/pre>\n<p>or<\/p>\n<pre lang=\"groovy\">\r\n<abc:testLink test=${condition} href=\"#\" class=\"abc\" style=\"color:#90B8FF;\"> \r\n     Text \r\n<\/abc:testLink>\r\n<\/pre>\n<p>_____________________<br \/>\nHitesh Bhatia<br \/>\nhitesh@intelligrape.com<br \/>\n_____________________<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(based on Tom\u00e1s Lin\u2019s truthlink) This is useful when one requires link on certain condition. Instead of first using condition tag and then tag for link these can be combined into one using taglib. text or Text Other way of doing this is by using taglib. class AbcTagLib { namespaces &#8220;abc&#8221;; def testLink = {attrs, [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[7],"tags":[4840,213],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/558"}],"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\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=558"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/558\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}