Skip navigation
All Places > Blackboard Developer Community > Blackboard Learn Developers > Blog > Author: Alberto Ruiz

There are a few template variables you can use to render platform, user or course information dynamically in contents, LTI custom params and other places. This is quite powerful, but it can be better...


With a custom template variable Building Block you can define new template variables to render virtually anything in your contents, from your Blackboard Learn instance using the API or taking data from the data base, or from an external system using web services, external data bases, etc... You can even render not only strings, but even html snippets to add dynamically, for instance, search forms from your Library service.


This is made by creating an extension Building Block, for what you have to include :


 <webapp-type value="javaext" />


in your bb-manifest.xml file.


You also have to declare in the same file your custom context handler, defining your extension with:


   <definition namespace="blackboard.platform">
    <extension id="customContextHandler"
      singleton="false" />


Then, in your source code, you create your custom context handler:



import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import blackboard.persist.BbPersistenceManager;
import blackboard.platform.context.Context;
import blackboard.platform.context.ContextEntry;
import blackboard.platform.context.ContextHandler;
import blackboard.util.resolver.Resolver;

//Extends ContextHandler class to include our variable resolver
public class CustomContextHandler implements ContextHandler {

  public CustomContextHandler() {

  public Entitlements getEffectiveEntitlements(Context ctx) {
       return new EntitlementList();

  public Entitlements getRestrictedEntitlements(Context ctx) {
       return null;

  public List<SecurityContext> getSecurityContexts(Context unused) {
       return new ArrayList<SecurityContext>();

  // Here is were we inyect our custom resolver
  public List<ContextEntry> resolveKeys(HttpServletRequest request,
  BbPersistenceManager unused) {
       CustomResolver resolver = new CustomResolver(request);
       return new LinkedList<ContextEntry>();



And now implement the custom resolver who contains the logic to show what you want where you insert your template variable:



import javax.servlet.http.HttpServletRequest;

import blackboard.platform.context.ContextManagerFactory;
import blackboard.util.resolver.ResolverComponent;

public class CustomResolver implements ResolverComponent {

  private static HttpServletRequest _request = null;

  public CustomResolver(HttpServletRequest request) {
       _request = request;

  public String[] getKeys() {

       return (new String[] { "variable_key" }); // the first part of the
                                                    // template variable (@X@
                                                    // tag) - variable_key in

  public String resolve(String method, String attributes[]) {
       String varout = null;

       if ("show".equalsIgnoreCase(method)) { // the second part of the @X@
                                                 // tag - show in
       try {

          String uriPrefix = Utils.getUriPrefix();
          // the code for inserting
          // the Unika search box
          varout = "Whatever you whant to show in your template variable <div></div><script></script>...";
          return varout;

       } catch (Exception e) {

       } finally {



       return null;




Now typing in your contents you will get the rendered html code you put in varout.


This technique has been very useful to me in different projects, so I hope this helps to somebody else.