0

Exists there a way to invoke a Perl sub from an incremental text template (HTML5)? Access of the data context and a bunch of variable works fine, but a sub call is required.

<p class="submit">
                [% IF page == "building_add " %]
                <input type="submit" value="[% l.submit %]" id="submit" />
                [% ELSIF page == "building_show" && ( (!auth_done) || (auth_done && check_access_rolebuilding(building_id,auth_user_id))) %]
                <input type="submit" value="[% l.change %]" id="submit" />
                [% END %]
</p>

check_access_rolebuilding will not be invoked. That's checked via debug output. Any advice?

mnemonic
  • 1,605
  • 2
  • 17
  • 26
  • 2
    If you're using [Template Toolkit](http://www.template-toolkit.org/), see [this SO question](http://stackoverflow.com/questions/1285441/calling-outside-modules-in-template-toolkit-without-plugins) for two solutions. – ThisSuitIsBlackNot Oct 11 '13 at 17:55
  • parse error :-( unexpected token (>), but your link will be checked out in addition – mnemonic Oct 11 '13 at 18:09

1 Answers1

1

Just add a reference to the subroutine into the hash of variables that you pass into the process() method.

# Your process() call might not look anything like this.
$tt->process(
  $template_name,
  {
    ... # existing variables
    check_access_rolebuilding => \&check_access_rolebuilding,
  },
) or die $tt->error;

Then within the template, you can use the check_access_rolebuilding() subroutine by just naming it as you have done in your example..

Dave Cross
  • 68,119
  • 3
  • 51
  • 97