The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Nile::View - The template processing system.

SYNOPSIS

                # get view home.html in current theme
                my $view = $self->me->view("home");
                # get view home.html in specific arabic
                my $view = $app->view("home", "arabic");
                
                # set view variables
                $view->var(
                                fname                   =>      'Ahmed',
                                lname                   =>      'Elsheshtawy',
                                email                   =>      'sales@mewsoft.com',
                                website         =>      'http://www.mewsoft.com',
                                singleline              =>      'Single line variable <b>Good</b>',
                                multiline               =>      'Multi line variable <b>Nice</b>',
                        );
                
                # set variable
                $view->set('email', 'sales@mewsoft.com');

                # get variable
                $email = $view->get('email');

                # automatic getter/setter for variables
                $view->email('sales@mewsoft.com');
                $view->website('http://www.mewsoft.com');
                $email = $view->email;
                $website = $view->website;

                # replace marked blocks or iterators
                $view->block("first", "1st Block New Content ");
                $view->block("six", "6th Block New Content ");
                
                # process variables and blocks and text language variables
                $view->process;

                # send the output to the browser
                $view->render;

DESCRIPTION

Nile::View - The template processing system.

view()

        my $view =  $self->me->view([$view, $theme]);

Creates new view object or returns the current view name. The first option is the view name with or without file extension $view, the default view extension is html. The second optional argument is the theme name, if not supplied the current default theme will be used.

lang()

        $view->lang('en-US');
        my $lang = $view->lang();

Sets or returns the language for processing the template text. Language must be already installed in the lang folder.

theme()

        $view->theme('arabic');
        my $theme = $view->theme();

Sets or returns the theme for loading template file. Theme must be already installed in the theme folder.

var() and set()

        $view->var(email=>'nile@cpan.org');
        $view->var(%vars);

        $view->var(
                        fname                   =>      'Ahmed',
                        lname                   =>      'Elsheshtawy',
                        email                   =>      'sales@domain.com',
                        website         =>      'http://www.mewsoft.com',
                        htmlnode                =>      'html code variable <b>Nile</b>',
                );

Sets one of more template variables. This method can be chained.

set()

        $view->set(email=>'nile@cpan.org');
        $view->set(%vars);

Same as method var() above.

get()

        $email = $view->get("email");
        @user = $view->get(qw(fname lname email website));

Returns one or more template variables values.

content()

        # get current template content
        $content = $view->content;

        # set current template content direct
        $view->content($content);

Get or set current template content.

block()

        # get all blocks as a hashref
        $blocks = $view->block;

        # get one block as a hashref
        $block = $view->block("first");
        
        # set a block new content
        $view->block("first", "1st Block New Content ");

Get and set blocks. Blocks or iterators are a block of the template code marked or processing and replacing with dynamic content. For example you can use blocks to show or hide a part of the template based on conditions. Another example is using nested blocks as iterators for displaying lists or tables of repeated rows.

replace()

        $view->replace('find text' => 'replaced text');
        $view->replace(%vars);

Replace some template text or code with another one. This method will replace all instances of the found text. This method can be chained.

replace()

        $view->replace('find text' => 'replaced text');
        $view->replace(%vars);

Replace some template text or code with another one. This method will replace only one instance of the found text. This method can be chained.

translate()

        # scan and replace the template language variables for the default 2 times
        $view->translate;

        # scan and replace the template language variables for 3 times
        $view->translate(3);

This method normally used internally when processing the template. It scans the tempalte for the langauge variables surrounded by the curly braces {var_name} and replaces them with their values from the loaded language files. This method can be chained.

process_vars()

        $view->process_vars;

This method normally used internally when processing the template. This method can be chained.

process_perl()

        $view->process_perl;

This method normally used internally when processing the template. This method can be chained.

capture()

        $view->capture($perl_code);

This method normally used internally when processing the template.

get_widget()

        $view->get_widget($widget, $theme);

This method normally used internally when processing the template. Returns the widget file content.

process_widgets()

        $view->process_widgets;

This method normally used internally when processing the template. This method can be chained.

process_plugins()

        $view->process_plugins ;

This method normally used internally when processing the template. This method can be chained.

parse()

        $view->parse;

This method normally used internally when processing the template. This method can be chained.

process_pass()

        $view->process_pass;

This method normally used internally when processing the template. This method can be chained.

process()

        $view->process;
        $view->process($passes);

Process the template. This method can be chained.

render()

        $view->render;

Send the template content to the browser. This method can be chained.

out()

        $view->out;

Process the template and return the content.

show()

        $view->show;
        
        # is the same as doing
        $view->process();
        $view->render();

Process the template and send the content to the browser.

header()

        $view->header;

Prints the header tot he browser.

Bugs

This project is available on github at https://github.com/mewsoft/Nile.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Nile.

SOURCE

Source repository is at https://github.com/mewsoft/Nile.

AUTHOR

Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com

COPYRIGHT AND LICENSE

Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, https://github.com/mewsoft/Nile, http://www.mewsoft.com

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.