z_template (zotonic_core v1.0.0-rc.17)

Template handling, compiles and renders django compatible templates using the template_compiler.

Summary

Functions

Return the list of all block names in a template. This only returns the list in the current template and not in the extended or overruled templates. Vars is needed for catinclude expands.

Disable debug points for the given context, this will flush all debug points for the context.

Enable debug points for the given template file. This will compile the template and return the module, or an error if it fails.

Return the template that the given template extends or overrules.

Return the list of all includes with a fixed template string in a template. Vars is needed for catinclude expands.

Check if the modulename looks like a module generated by the template compiler.

Lookup the module for a compiled template. This will compile the template if it was not yet compiled.

Observer, triggered when there are new module files indexed

Render a block template to an iolist().

Render a template to an iolist(). This removes all scomp state etc from the rendered html and appends the information in the scomp states to the context for later rendering.

Force a reset of all templates, used after a module has been activated or deactivated.

Return the module of a compiled template. This will compile the template if it was not yet compiled. Vars is needed for catinclude expands.

Functions

blocks(Template, Vars, Context)

-spec blocks(Template, Vars, Context) -> {ok, Blocks} | {error, term()}
                when
                    Template ::
                        template_compiler:template() |
                        #module_index{key ::
                                          #module_index_key{site :: atom(),
                                                            type ::
                                                                z_module_indexer:key_type() | undefined,
                                                            name ::
                                                                atom() | binary() | {binary(), binary()}},
                                      filepath :: file:filename_all() | undefined,
                                      module :: atom() | undefined,
                                      erlang_module :: atom() | undefined,
                                      tag :: integer() | undefined},
                    Vars :: list() | map(),
                    Context :: z:context(),
                    Blocks :: [atom()].

Return the list of all block names in a template. This only returns the list in the current template and not in the extended or overruled templates. Vars is needed for catinclude expands.

disable_debug_points(Context)

-spec disable_debug_points(Context) -> ok when Context :: z:context().

Disable debug points for the given context, this will flush all debug points for the context.

enable_debug_points(Filename, DebugPoints, Context)

-spec enable_debug_points(Filename, DebugPoints, Context) -> {ok, Module} | {error, Reason}
                             when
                                 Filename :: binary() | string(),
                                 DebugPoints :: [{Line, Col}],
                                 Line :: integer(),
                                 Col :: integer(),
                                 Context :: z:context(),
                                 Module :: module(),
                                 Reason :: term().

Enable debug points for the given template file. This will compile the template and return the module, or an error if it fails.

extends(Template, Vars, Context)

-spec extends(Template, Vars, Context) -> {ok, Extends} | {error, term()}
                 when
                     Template ::
                         template_compiler:template() |
                         #module_index{key ::
                                           #module_index_key{site :: atom(),
                                                             type ::
                                                                 z_module_indexer:key_type() | undefined,
                                                             name ::
                                                                 atom() |
                                                                 binary() |
                                                                 {binary(), binary()}},
                                       filepath :: file:filename_all() | undefined,
                                       module :: atom() | undefined,
                                       erlang_module :: atom() | undefined,
                                       tag :: integer() | undefined},
                     Vars :: list() | map(),
                     Context :: z:context(),
                     Extends :: undefined | binary() | overrules.

Return the template that the given template extends or overrules.

includes(Template, Vars, Context)

-spec includes(Template, Vars, Context) -> {ok, Includes} | {error, term()}
                  when
                      Template ::
                          template_compiler:template() |
                          #module_index{key ::
                                            #module_index_key{site :: atom(),
                                                              type ::
                                                                  z_module_indexer:key_type() |
                                                                  undefined,
                                                              name ::
                                                                  atom() |
                                                                  binary() |
                                                                  {binary(), binary()}},
                                        filepath :: file:filename_all() | undefined,
                                        module :: atom() | undefined,
                                        erlang_module :: atom() | undefined,
                                        tag :: integer() | undefined},
                      Vars :: list() | map(),
                      Context :: z:context(),
                      Includes :: [map()].

Return the list of all includes with a fixed template string in a template. Vars is needed for catinclude expands.

is_template_module(Module)

-spec is_template_module(binary() | string() | atom()) -> boolean().

Check if the modulename looks like a module generated by the template compiler.

lookup(Filename, Context)

-spec lookup(Filename, Context) -> {ok, Module} | {error, term()}
                when Filename :: binary() | string(), Context :: z:context(), Module :: module().

Lookup the module for a compiled template. This will compile the template if it was not yet compiled.

module_reindexed(_, Context)

-spec module_reindexed(module_reindexed,
                       #context{cowreq :: cowboy_req:req() | undefined,
                                cowenv :: cowboy_middleware:env() | undefined,
                                site :: atom(),
                                controller_module :: atom() | undefined,
                                client_id :: binary() | undefined,
                                client_topic :: mqtt_sessions:topic() | undefined,
                                routing_id :: binary() | undefined,
                                acl :: term() | admin | undefined,
                                acl_is_read_only :: boolean(),
                                user_id :: integer() | authenticated | undefined,
                                render_state :: undefined | z_render:render_state(),
                                db :: {atom(), atom()} | undefined,
                                dbc :: pid() | undefined,
                                language :: [atom()],
                                tz :: binary(),
                                props :: map(),
                                depcache :: pid() | atom(),
                                dispatcher :: pid() | atom(),
                                template_server :: pid() | atom(),
                                scomp_server :: pid() | atom(),
                                dropbox_server :: pid() | atom(),
                                pivot_server :: pid() | atom(),
                                module_indexer :: pid() | atom(),
                                translation_table :: atom()}) ->
                          ok.

Observer, triggered when there are new module files indexed

render(Render, Context)

-spec render(#render{template :: template_compiler:template(),
                     is_all :: boolean(),
                     vars :: proplists:proplist()},
             #context{cowreq :: cowboy_req:req() | undefined,
                      cowenv :: cowboy_middleware:env() | undefined,
                      site :: atom(),
                      controller_module :: atom() | undefined,
                      client_id :: binary() | undefined,
                      client_topic :: mqtt_sessions:topic() | undefined,
                      routing_id :: binary() | undefined,
                      acl :: term() | admin | undefined,
                      acl_is_read_only :: boolean(),
                      user_id :: integer() | authenticated | undefined,
                      render_state :: undefined | z_render:render_state(),
                      db :: {atom(), atom()} | undefined,
                      dbc :: pid() | undefined,
                      language :: [atom()],
                      tz :: binary(),
                      props :: map(),
                      depcache :: pid() | atom(),
                      dispatcher :: pid() | atom(),
                      template_server :: pid() | atom(),
                      scomp_server :: pid() | atom(),
                      dropbox_server :: pid() | atom(),
                      pivot_server :: pid() | atom(),
                      module_indexer :: pid() | atom(),
                      translation_table :: atom()}) ->
                template_compiler:render_result().

render(Template, Vars, Context)

-spec render(template_compiler:template() |
             #module_index{key ::
                               #module_index_key{site :: atom(),
                                                 type :: z_module_indexer:key_type() | undefined,
                                                 name :: atom() | binary() | {binary(), binary()}},
                           filepath :: file:filename_all() | undefined,
                           module :: atom() | undefined,
                           erlang_module :: atom() | undefined,
                           tag :: integer() | undefined},
             list() | map(),
             #context{cowreq :: cowboy_req:req() | undefined,
                      cowenv :: cowboy_middleware:env() | undefined,
                      site :: atom(),
                      controller_module :: atom() | undefined,
                      client_id :: binary() | undefined,
                      client_topic :: mqtt_sessions:topic() | undefined,
                      routing_id :: binary() | undefined,
                      acl :: term() | admin | undefined,
                      acl_is_read_only :: boolean(),
                      user_id :: integer() | authenticated | undefined,
                      render_state :: undefined | z_render:render_state(),
                      db :: {atom(), atom()} | undefined,
                      dbc :: pid() | undefined,
                      language :: [atom()],
                      tz :: binary(),
                      props :: map(),
                      depcache :: pid() | atom(),
                      dispatcher :: pid() | atom(),
                      template_server :: pid() | atom(),
                      scomp_server :: pid() | atom(),
                      dropbox_server :: pid() | atom(),
                      pivot_server :: pid() | atom(),
                      module_indexer :: pid() | atom(),
                      translation_table :: atom()}) ->
                template_compiler:render_result().

render_block(Block, Render, Context)

-spec render_block(atom(),
                   #render{template :: template_compiler:template(),
                           is_all :: boolean(),
                           vars :: proplists:proplist()},
                   #context{cowreq :: cowboy_req:req() | undefined,
                            cowenv :: cowboy_middleware:env() | undefined,
                            site :: atom(),
                            controller_module :: atom() | undefined,
                            client_id :: binary() | undefined,
                            client_topic :: mqtt_sessions:topic() | undefined,
                            routing_id :: binary() | undefined,
                            acl :: term() | admin | undefined,
                            acl_is_read_only :: boolean(),
                            user_id :: integer() | authenticated | undefined,
                            render_state :: undefined | z_render:render_state(),
                            db :: {atom(), atom()} | undefined,
                            dbc :: pid() | undefined,
                            language :: [atom()],
                            tz :: binary(),
                            props :: map(),
                            depcache :: pid() | atom(),
                            dispatcher :: pid() | atom(),
                            template_server :: pid() | atom(),
                            scomp_server :: pid() | atom(),
                            dropbox_server :: pid() | atom(),
                            pivot_server :: pid() | atom(),
                            module_indexer :: pid() | atom(),
                            translation_table :: atom()}) ->
                      template_compiler:render_result().

render_block(OptBlock, Template, Vars, Context)

-spec render_block(atom(),
                   template_compiler:template() |
                   #module_index{key ::
                                     #module_index_key{site :: atom(),
                                                       type :: z_module_indexer:key_type() | undefined,
                                                       name :: atom() | binary() | {binary(), binary()}},
                                 filepath :: file:filename_all() | undefined,
                                 module :: atom() | undefined,
                                 erlang_module :: atom() | undefined,
                                 tag :: integer() | undefined},
                   list() | map(),
                   #context{cowreq :: cowboy_req:req() | undefined,
                            cowenv :: cowboy_middleware:env() | undefined,
                            site :: atom(),
                            controller_module :: atom() | undefined,
                            client_id :: binary() | undefined,
                            client_topic :: mqtt_sessions:topic() | undefined,
                            routing_id :: binary() | undefined,
                            acl :: term() | admin | undefined,
                            acl_is_read_only :: boolean(),
                            user_id :: integer() | authenticated | undefined,
                            render_state :: undefined | z_render:render_state(),
                            db :: {atom(), atom()} | undefined,
                            dbc :: pid() | undefined,
                            language :: [atom()],
                            tz :: binary(),
                            props :: map(),
                            depcache :: pid() | atom(),
                            dispatcher :: pid() | atom(),
                            template_server :: pid() | atom(),
                            scomp_server :: pid() | atom(),
                            dropbox_server :: pid() | atom(),
                            pivot_server :: pid() | atom(),
                            module_indexer :: pid() | atom(),
                            translation_table :: atom()}) ->
                      template_compiler:render_result().

render_block_to_iolist(Block, File, Vars, Context)

-spec render_block_to_iolist(atom(), template_compiler:template(), list() | map(), z:context()) ->
                                {iolist(), z:context()}.

Render a block template to an iolist().

render_to_iolist(File, Vars, Context)

-spec render_to_iolist(template_compiler:template() |
                       #module_index{key ::
                                         #module_index_key{site :: atom(),
                                                           type ::
                                                               z_module_indexer:key_type() | undefined,
                                                           name ::
                                                               atom() | binary() | {binary(), binary()}},
                                     filepath :: file:filename_all() | undefined,
                                     module :: atom() | undefined,
                                     erlang_module :: atom() | undefined,
                                     tag :: integer() | undefined},
                       list() | map(),
                       z:context()) ->
                          {iolist(), z:context()}.

Render a template to an iolist(). This removes all scomp state etc from the rendered html and appends the information in the scomp states to the context for later rendering.

reset(Site)

-spec reset(atom() |
            #context{cowreq :: cowboy_req:req() | undefined,
                     cowenv :: cowboy_middleware:env() | undefined,
                     site :: atom(),
                     controller_module :: atom() | undefined,
                     client_id :: binary() | undefined,
                     client_topic :: mqtt_sessions:topic() | undefined,
                     routing_id :: binary() | undefined,
                     acl :: term() | admin | undefined,
                     acl_is_read_only :: boolean(),
                     user_id :: integer() | authenticated | undefined,
                     render_state :: undefined | z_render:render_state(),
                     db :: {atom(), atom()} | undefined,
                     dbc :: pid() | undefined,
                     language :: [atom()],
                     tz :: binary(),
                     props :: map(),
                     depcache :: pid() | atom(),
                     dispatcher :: pid() | atom(),
                     template_server :: pid() | atom(),
                     scomp_server :: pid() | atom(),
                     dropbox_server :: pid() | atom(),
                     pivot_server :: pid() | atom(),
                     module_indexer :: pid() | atom(),
                     translation_table :: atom()}) ->
               ok.

Force a reset of all templates, used after a module has been activated or deactivated.

start_link(Site)

template_module(Template, Vars, Context)

-spec template_module(Template, Vars, Context) -> {ok, Module} | {error, term()}
                         when
                             Template ::
                                 template_compiler:template() |
                                 #module_index{key ::
                                                   #module_index_key{site :: atom(),
                                                                     type ::
                                                                         z_module_indexer:key_type() |
                                                                         undefined,
                                                                     name ::
                                                                         atom() |
                                                                         binary() |
                                                                         {binary(), binary()}},
                                               filepath :: file:filename_all() | undefined,
                                               module :: atom() | undefined,
                                               erlang_module :: atom() | undefined,
                                               tag :: integer() | undefined},
                             Vars :: list() | map(),
                             Context :: z:context(),
                             Module :: module().

Return the module of a compiled template. This will compile the template if it was not yet compiled. Vars is needed for catinclude expands.