Parsing of Liferay template files

Source: Internet
Author: User
Tags definition continue

As we all know, Liferay's core framework consists of a set of velocity template files located in the $liferay_home\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\webapps\root\ Html\themes\classic\templates Directory, some colleagues today asked me where the variables in these templates are defined.

In order to solve this problem, we found the Portal-impl.jar in the Velocityvariableimpl class file, so at a glance. Because the first line in PORTAL-NORMAL.VM resolves other files, the parsed file is in variable init, as follows:

<! DOCTYPE html> 
      
#parse ($init) 
      

See 03 lines, and the parsed file defines the variables used in most templates, so where is this file? We can see the definition in Velocityvariableimpl:

Velocitycontext.put ( 
    "Init",  
    themedisplay.getpathcontext () + "  
    _servlet_context_" + "  
    /html/themes /_UNSTYLED/TEMPLATES/INIT.VM "); 
      
  Velocitycontext.put ( 
    "Portletgroupid", New Long (Themedisplay.getscopegroupid ())); 
} 
      
Theme Theme = (Theme) request.getattribute ("Theme");

So, the file represented by the parse init variable is/HTML/THEMES/_UNSTYLED/TEMPLATES/INIT.VM in the ROOT application, and we open it, and sure enough it's all variable definitions:

Because this file is very long, so here is omitted

# #----------Common Variables----------# # 
      
#set ($theme _display = $themeDisplay) 
#set ($portlet _display = $po Rtletdisplay) 
      
#set ($theme _timestamp = $themeDisplay. Gettheme (). Gettimestamp ()) 
#set ($theme _settings = $ Themedisplay.getthemesettings ()) 
      
...

Conclusion:

The variables in the template file in the Liferay framework, most of which are defined in INIT.VM, are defined directly in the Velocityvariableimpl class

Actual combat:

For example, my colleague asked me where the $content _include variable in PORTAL-NORMAL.VM's 第47-53 line is defined:

#if ($selectable) 
    $theme. Include ($content _include) 
#else
    $portletDisplay. Recycle () 
      
    $ Portletdisplay.settitle ($the _title) 
      
    $theme. Wrapportlet ("PORTLET.VM", $content _include) 
#end

We're looking in the INIT.VM, and it's not hard to find this variable defined as:

#set ($bottom _include = "$dir _include/common/themes/bottom.jsp") 
#set ($bottom _ext_include = $bottom _include) 
#set ($content _include = "$dir _include$tilescontent") 
#set ($top _head_include = "$dir _include/common/ Themes/top_head.jsp ") 
#set ($top _messages_include =" $dir _include/common/themes/top_messages.jsp ")

Is $dir _include$tilescontent, so we still need to continue to parse it recursively:

We continue to look in the INIT.VM, not hard to find the variable definition of $dir_include:

#if ($is _portlet_page && $theme _display.iswaptheme ()) 
                #set ($dir _include = "/wap") 
#else
                #set ($dir _include = "/html") 
#end

So, because our official default example is not WAP, so $dir_include for/html

Next we look for the definition of $tilescontent. Unfortunately, it's not defined in the INIT.VM, so we go back to the Velocityvariableimpl class, and here we find the definition:

String tilescontent = (string) componentcontext.getattribute ("content"); 
      
Themedisplay.settilescontent (tilescontent); 
      
Velocitycontext.put ("Tilescontent", tilescontent);

So, $tilesContent is a variable that is dynamically passed over during a program's run:

To sum up: Colleagues asked my portal-normal.vm file in the $content_include variable value, is in the program running dynamic resolution, by default, it is "/html" and the program runtime dynamically get the content property value, Then these 2 values are spliced together to get the value.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.