Gila API

chm.GilaCompile

This function is provided by Gila view engine (pronounced Hila). It is mainly used by RenderView SPROC to render a view defined in chameleon.Views table. It receives name of a view together with its content, parses it and returns compiled view in T-SQL language as a nvarchar(max) string.

      CREATE FUNCTION [chm].[GilaCompile]
(
    @context_id     INT,
    @viewName       NVARCHAR (200),
    @viewContent    NVARCHAR (MAX)
)
RETURNS NVARCHAR (MAX)
    

Parameters:

  • @context_id: context_id of current request. It enables a view to access context-related data such as current request url, routing values, request headers and cookies, etc. In order to learn more about context-id click here.
  • @viewName: name of the view to be compiled.
  • @viewContent: content of the view.

After RenderView SPROC calls GilaCompile, it executes the compiled code which as stated earlier is in T-SQL language.

Example:

      declare @content nvarchar(max)
declare @compiledContent nvarchar(max)

set @content = N'<h1><%=''Hello from Chameleon!''%></h1>'

set @compiledContent = chm.GilaCompile(1, 'test', @content)

print @compiledContent
    

The following is the output printed after executing above example.

      set @__result = ''

set @__result = @__result + N'<h1>'
set @__result = @__result + chm.HtmlEncode('Hello from Chameleon!')
set @__result = @__result + N'</h1>'
    

This code can be executed using sp_executesql system procedure.

      ...
declare @renderedContent nvarchar(max)

exec sp_executesql @compiledContent, N'@__result nvarchar(max) out', @__result = @renderedContent out

select @renderedContent
    

Note: Here we used an arbitrary value for @context_id parameter since we are manually calling GilaCompile. In practice, the GilaCompile UDF is intended to be called by Chameleon to render and return a view defined in chameleon.Views table. Developers do not need to manually call this UDF.

In order to learn more about Gila view engine, click here.

Gila Settings

Gila view engine and hence GilaCompile execution can be customized by a few settings. GilaCompile looks for a setting named Chamaleon.ViewEngine.Gila in chameleon.Settings table to retrieve its settings. The setting is expected to be a GilaViewEngineConfig in JSON format. Details of GilaViewEngineConfig is explained here.

After reading the Chamaleon.ViewEngine.Gila setting, GilaCompile deserializes it as a GilaViewEngine object, creates a GilaViewEngine instance and passes GilaViewEngineConfig object to its constructor upon instantiation.

If Chamaleon.ViewEngine.Gila is empty, GilaCompile passes a default GilaViewEngineConfig object to GilaViewEngine instance.