Webman-framework

Lightweight, Component-based, and Database-oriented Web Application Framework

About | Overview | Documentation

 

Documentation > Modules and APIs > HTML_Link_Menu

HTML_Link_Menu

 

Description:

The core module to dynamically generate web application menu using standard HTML hypertext links. The hypertext links generated are mainly used to provide users an access points to application services via HTTP-GET method.

 

Dependencies:

Webman-framework's Core Modules:

  • Template_Element_Extractor (Composition)

 

1. View Template

Following Webman-framework's "Convention over Configuration" (CoC) the view template to render HTML_Link_Menu result content is simply a start_menu type template element with a series of menu_item0_, ..., menu_itemn_ template word patterns as its content place-holder. The template element can be later manipulated inside the process_MENU hook function (see section 3).

<html>
<body>
<!-- start_view_ //-->
<!-- start_menu_ name=mainlinks //-->
menu_item0_ | ... | menu_itemn_
<!-- end_menu_ //-->
<!-- end_view_ //-->
</body>
</html>



 
2. Instantiation and Basic Parameter Setting


my $html_menu = new HTML_Link_Menu;


2.1 Links, Captions, and Attributes.

The next two functions are mandatorily to be called just after the instantiation or the module can't generate the intended menu links. The @menu_items is an array of the link captions while @menu_links is an array of the links attributes. The link attributes normally a CGI CGI parameters passed via HTTP-GET method. The link attribute should be the uniques one which can't be automatically generated by the module itself (see section 2.2).

$html_menu->set_Menu_Items(@menu_items);
$html_menu->set_Menu_Links(@menu_links);


2.2 Basic and Additional Links Attributes

Function to automatically set the basic standard link items attributes. The script name "index.cgi" is the default CGI main script name in Webman-framework. The argument $link_ref_name is the link attribute name used to refer to current selected link item name. It will exist as CGI parameter passed over via HTTP-GET method.

$html_menu->set_Auto_Menu_Links("index.cgi", $link_ref_name);

Other additional GET-data attributes which are indentical for all link items can be added using the next function.
$html_menu->add_GET_Data_Links_Source("param_1=value_1&...&param_n=value_n");


2.3 Current Selected Link Item

The argument $current_selected_link is the current selected link item name. Using the previous setting (section 2.2 above) it's possible to have its value from $cgi->param($link_ref_name) function call.

$html_menu->set_Active_Menu_Item($current_selected_link);



 
3. Implementation Inside Hook Function

In most cases, link menu items generation from application's main link structure does not requires this type of hook function implementatiom since it has been conveniently supported by webman_dynamic_links framework's component type module.

sub process_MENU { 
    my $this = shift @_;
    my $te = shift @_;

    my $cgi = $this->get_CGI;
    my $dbu = $this->get_DBU;
    my $db_conn = $this->get_DB_Conn;
    
    my $te_content = $te->get_Content;
    my $te_type_num = $te->get_Type_Num;
    my $te_type_name = $te->get_Name;
    
    ### The "link_id" argument is Webman-framework's standard CGI parameter 
    ### name that refer to current link item selected from the application 
    ### main link structure. It will be passed as an additional GET-data to  
    ### dynamic link items to be generated below. So, each click on them will  
    ### point back to current selected application's main link item.
    my $link_id = $cgi->param("link_id");
    
    if ($te_type_name eq "mainlinks") {
        ### Set menu's link items and their unique attributes.
        my @menu_items = ("Home", "Download", "Documentation");
        my @menu_links = ("url=/home", "url=/download", "url=/doc");    

        ### Start using module to generate dynamic links.
        my $html_menu = new HTML_Link_Menu;

        $html_menu->set_Menu_Items(@menu_items);
        $html_menu->set_Menu_Links(@menu_links);
        
        $html_menu->set_Auto_Menu_Links("index.cgi", "page");
        $html_menu->add_GET_Data_Links_Source("link_id=$link_id");
        $html_menu->set_Active_Menu_Item($cgi->param("page"));
        
        $html_menu->set_Menu_Template_Content($te_content);
        my $content = $html_menu->get_Menu;

        $this->add_Content($content);
    } 
}