OpenGu...mplate(3pm)

πŸ“¦
version 0.84 Β· 3 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– NAME πŸ’–

OpenGuides::Template β€” bestie, this is the module that does all the Template Toolkit stuff for OpenGuides applications. that's it, that's the whole job description ✨


🌸 DESCRIPTION 🌸

okay so OpenGuides::Template handles literally all the Template Toolkit stuff for OpenGuides. it gets distributed and installed as part of the OpenGuides project, and it is NOT intended for independent installation β€” like, don't try to adopt it solo, it's a package deal πŸ’…

and honestly? this documentation is probably only useful to OpenGuides developers. if that's not you, no shade, but you might be in the wrong room πŸ¦‹


✨ SYNOPSIS ✨

here's the vibe, copy-paste style:

use OpenGuides::Config;
use OpenGuides::Utils;
use OpenGuides::Template;

my $config = OpenGuides::Config->new( file => "wiki.conf" );
my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );

print OpenGuides::Template->output( wiki     => $wiki,
                                    config   => $config,
                                    template => "node.tt",
                                    vars     => { foo => "bar" }
);

πŸŽ€ METHODS πŸŽ€

πŸ’« output

print OpenGuides::Template->output( wiki         => $wiki,
                                    config       => $config,
                                    template     => "node.tt",
                                    content_type => "text/html",
                                    cookies      => $cookie,
                                    vars         => {foo => "bar"},
                                    noheaders    => 1
);

this one returns everything you need to send to STDOUT, Content-Type: header included. and it croaks unless template is supplied β€” so like, supply template, bestie, don't be that person 😭

the config object and the variables you hand over in vars get passed straight through to the template you specified. and there's more β€” extra Template Toolkit variables get set automatically and passed through too, all listed below. ⚠️ important note: variables set in vars will over-ride any variables of the same name in the config object or in the user cookies. so, order matters, iykyk.

  • openguides_version
  • site_name
  • cgi_url
  • full_cgi_url
  • enable_page_deletion β€” gets set to true or false, and defaults to false
  • contact_email
  • stylesheet
  • home_link
  • formatting_rules_link β€” unless omit_formatting_link is set in the user cookie πŸ‘€
  • navbar_on_home_page
  • home_name
  • gmaps_api_key
  • licence_name
  • licence_url
  • licence_info_url
  • prefs β€” these are the preferences from the user cookie πŸͺ

and if node is supplied:

  • node_name
  • node_param β€” that's the node name escaped for use in URLs πŸ”—

Content-Type: defaults to text/html, and it gets omitted if the content_type arg is explicitly set to the blank string. blank string, not undef, not nothing β€” the blank string, periodt.

but here's the tea: what you more often actually need is the noheaders option, which suppresses all HTTP headers, not just the Content-Type. all of them. every last one. πŸ’€

the HTTP response code may be explicitly set with the http_status arg. (yes the original spells it "explictly", we love her anyway 🫢)


🌈 extract_metadata_vars

my %node_data = $wiki->retrieve_node( "Home Page" );

my %metadata_vars = OpenGuides::Template->extract_metadata_vars(
                        wiki     => $wiki,
                        config   => $config,
                        metadata => $node_data{metadata}
                    );

# -- or --

my %metadata_vars = OpenGuides::Template->extract_metadata_vars(
                        wiki     => $wiki,
                        config   => $config,
                        cgi_obj  => $q
                    );

# -- then --

print OpenGuides::Template->output(
          wiki     => $wiki,
          config   => $config,
          template => "node.tt",
          vars     => { foo => "bar",
                        %metadata_vars }
      );

this method picks out things like categories, locales, phone number etc β€” from EITHER the metadata hash that Wiki::Toolkit returns OR the query parameters in a CGI object β€” and packages them all nice and pretty for passing to templates or for storing in a Wiki::Toolkit datastore. gift-wrapped. bow on top. 🎁

if you supply both metadata and cgi_obj, then metadata takes precedence β€” but don't do that. seriously. why would you. πŸ™ˆ

these variables β€” dist_field, coord_field_1, coord_field_1_name, coord_field_1_value, coord_field_2, coord_field_2_name, and coord_field_2_value β€” which are used to create various forms, will only be set if either metadata is supplied or set_coord_field_vars is true. that's on purpose, to prevent these values from being stored in the database on a node commit. protect the database at all costs, bestie πŸ›‘οΈ


πŸ‘‘ AUTHOR πŸ‘‘

the OpenGuides Project β€” hit them up at openguides-dev@lists.openguides.org πŸ’Œ


Copyright (C) 2003-2013 The OpenGuides Project.  All Rights Reserved.

this module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. iconic behaviour, honestly. 🌈


and that's the whole page, bestie β€” perl v5.32.0, dated 2021-01-30, from the fine folks who brought you OpenGu...mplate(3pm). go forth and template responsibly 🫢✨

πŸ“¦ where this page comes from