Knowledge is power. We love to share it.

News related to Mono products, services and latest developments in our community.

dbracun

Customizing templates for LLBLGen ANGTE

03/30/2012

LLBLGen ANGTE (short for “ASP.Net GUI Templates Extended”) is a template set for GUI generation that can be used in your LLBLGen projects as a complete database editor using Adapter or SelfServicing generated code. Keep in mind that, although LLBLGen Pro v.3x supports multiple target frameworks, at the time of writing this post these templates only work for LLBLGen Pro target framework.

The implementation and usage of ANGTE templates is explained here, so I will not go into details. Instead of that, the purpose of this post is to explain how to add custom features in templates that you need in your projects.

Templates consist of control blocks. Standard control blocks are described as sections of code that generate parts of output files (or complete files). Each standard control block is delimited by the symbols <% … %>.

For example:

<% if(SD_GeneralUtilsGuiFiles.AllowAddNew(entityGuiInfo)) { %>
<asp:Button ID="btnAddNew" runat="server" Text="Add new" SkinID="ButtonSkin" OnClick="btnAddNew_Click"/>
<% } %>

In the previous example, the generator checks whether the GUI information  file indicates that a certain entity allows adding new records. If it is set to true, the following output will be generated:

<asp:Button ID="btnAddNew" runat="server" Text="Add new" SkinID="ButtonSkin" OnClick="btnAddNew_Click"/>

Furthermore, ANGTE also supports expression control blocks that evaluate expressions and convert them to strings. This is than inserted into the output file. Expression control blocks are delimited by symbols <%= … %>.

Example:

<asp:Label ID="lbl<%=field.Name%>" runat="server" Text="Label"/>

In this example our generator will take the name of a field and convert it to string (example: if field’s name is Example, than ID will be lblExample).

If you are wondering how to define methods in one template file that are to be used from other files:

1. There are two template files already defined in Templates folder (files: generalUtils.lpt and generalUtilsGuiFiles.lpt) that hold methods that are used by the generator, therefore you should check if the method that you need is already defined within those files. If not, you can insert your methods there.

Example:

public static bool FieldNameExists(XElement entityGuiInfo, IFieldElementCore field) {
    bool fieldExits = false;
    if (entityGuiInfo != null)
    {
        var value =  entityGuiInfo.Descendants("Field")
            .Where(node => node.Attribute("Name").Value == field.Name)
            .Select(node => node.Value.ToString()).FirstOrDefault();       
        if (value != null)
        {
            fieldExits = true;
        }
    }
    return fieldExits;
}

2. Before your method can be used, you must first find the template ID of a template file that holds your method. Template ID’s are defined in Templates folder, in the file SD.AdditionalTemplates.DbEditor.NET20.templatebindings. For example, my method is defined in generalUtilsGuiFiles.lpt and template ID of that file is SD_GeneralUtilsGuiFiles.

3. Now when you finally inserted a method and you know a template ID, simply call your method as shown in the following example.

<%
EntityDefinition currentEntity = (EntityDefinition)_activeObject;
var entityFields = currentEntity.GetAllFieldsInElement(true, false).Where(f=>f.FieldType.KindOfType==FieldTypeKind.DotNetType).OrderBy(f=>f.Name);
foreach(var field in entityFields)
{
    if(SD_GeneralUtilsGuiFiles.FieldNameExists(entityGuiInfo, field))
    { %>
         //write your code
   <% }
}%>
This content has not been rated yet.