Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to declare a function inside GSP?

How can I declare a function inside GSP? I need something like taglib but declared inside GSP - it doesn't matter outside

like image 613
fedor.belov Avatar asked Feb 07 '12 08:02

fedor.belov


1 Answers

You can't define methods in GSPs. But you can have anonymous functions if you want :D

Example:

<%
    def prettify = { "***$it***" }
%>
<h1>${prettify(someText)}</h1>

Though this example doesn't make too much sense, as that little formatting could be inlined. For any kind of extra logic for the views, I would follow OverZealous recommendation and use a taglib.

like image 148
epidemian Avatar answered Sep 30 '22 05:09

epidemian