Using a template file

English! place to talk about development, programming and coding
Post Reply
bendenn
Znuny newbie
Posts: 35
Joined: 25 May 2012, 11:09
Znuny Version: 3.1.6
Real Name: Ben

Using a template file

Post by bendenn »

hello,
could use a little help.
i try this:
------------------
http://doc.otrs.org/developer/3.0/en/html/hacking.html
Using a template file
Ok, but how to actually process a template file and generate the result? This is really simple ^ ^:

# Render AdminState.dtl
$ Output = $ self-> {Object} layout -.> Output (
     Template File => 'Admin State',
     Data => \% param,
);
    
In the frontend modules, the output () function of Kernel :: Output :: HTML :: Layout is called (after all the needed blocks have been called into this template) to generate the final output. An optional set of data parameters is not passed to the template, inserting data for all commands Which are inside of a block.

The source code of this document can be found at source.otrs.org.
-------------------

but i get this
Error message: Global symbol "$ output" requires explicit package name at C :/ Program 2/OTRS/OTRS / [..]

which is the package name?
what am I doing wrong?

greeting
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Using a template file

Post by reneeb »

Can you show more code?

If you want to develop a new feature (a new module) for OTRS you need (at least) three files: the configuration file, the module and the template.

In the configuration file you have to enable the frontend module. You can do it either with a perl module or with an XML file. If you do it the XML way, you can change the settings via SysConfig. With the Perl way you can't...

For the beginning it is easier with the Perl file. Create Kernel/Config/Files/Calendar.pm

Code: Select all

# module reg and nav bar
$Self->{'Frontend::Module'}->{'AgentCalendar'} = {
    Description => 'Calendar',
    NavBarName => 'Ticket',
    NavBar => [
        {
            Description => 'Calendar',
            Name => 'Calendar',
            Image => 'calendar.png',
            Link => 'Action=AgentCalendar',
            NavBar => 'Ticket',
            Prio => 5000,
            AccessKey => 'c',
        },
    ],
};
You have to replace 'Calendar' with the module name.

You module has to be located in Kernel/Modules and it has to provide two methods: 'new' and 'Run'. In the new method the object is created and it checks if it has all needed stuff:

Code: Select all

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {%Param};
    bless( $Self, $Type );

    # set debug
    $Self->{Debug} = 0;

    # check all needed objects
    for my $Needed (qw(ParamObject DBObject LayoutObject ConfigObject LogObject)) {
        if ( !$Self->{$Needed} ) {
            $Self->{LayoutObject}->FatalError( Message => "Got no $Needed!" );
        }
    }

    # hier evtl. weitere notwendige Objekte erzeugen

    return $Self;
}
The Run method actually adds functionality to the feature. An example:

Code: Select all

sub Run {
    my ( $Self, %Param ) = @_;

    my $Output = $Self->{LayoutObject}->Output(
        TemplateFile => 'Contact',
        Data         => \%Param,
    );
}
And in Kernel/Output/HTML/Standard, you need (in this example) a 'Contact.dtl'.

I saw in your profile, that you speak German, so this might be interesting to you: http://otrs.perl-services.de/workshop.html
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
bendenn
Znuny newbie
Posts: 35
Joined: 25 May 2012, 11:09
Znuny Version: 3.1.6
Real Name: Ben

Re: Using a template file

Post by bendenn »

that works.
solved ...
Thank you very much
Post Reply