Templating > alahup! useful functions and variables

These are the most useful functions/variables that you will be using most of the time in a main template:

  • {link > outputs the href of an internal link. Use it like this:

    <a class="br0">{link class="st0">""}">Home</a>
    <a class="br0">{link class="st0">"products"}">Products</a>
  • test_context modifier allows testing of the current url.

    {if "products"|test_context}You are in products section !{/if}

    You can test an url strictly with test_context:strict

    {if "products"|test_context:strict}You are exactly on products home page{/if}
  • $alahup->blockExists(2) returns 1 if a block is defined in zone with id=2 .

    {if $alahup->blockExists(2)}
      this is the block in zone 2 :
      {alahup->block zone="2"}
    {/if}
  • {alahup->block zone="2"} renders and outputs the block in zone with id=2.

    You can render a block from another url than the current one:

    {alahup->block zone="2" url="someother/place"}

Constants

alahup! constants are of the form AH_SOMEVARIABLE.

They can be read from the php code (in alahup/_main.php for example), or from the template using $smarty.const.AH_SOMEVARIABLE.

  • AH_HREF contains the current url. (i.e. "en/products/alahup")

    templates/main.tpl :
    German version :
    {alahup->block zone="1" url="de"|cat:"/"|cat:$smarty.const.AH_HREF}
  • AH_STATUS contains the status of the site. Can be "work" if we are in the draft work site, "checkout" in the checkout site, "published" in the published version of the site.

    Example : protecting some part of the site, but not in the draft work site.

    _main.php :
    if ( AH_STATUS == 'published' )
    {
     $protected_url = 'documentation/restricted';
     if (preg_match("'$protected_url($|[/]|\?)'", AH_HREF) || $protected_url == '')
     {
     if ( !isset($_SERVER['PHP_AUTH_USER']) )
     {
      header("WWW-authenticate: basic realm=\"RESTRICTED AREA\"");
      header("HTTP/1.0 401 Unauthorized")
      exit;
     } else
     {
     if ( ($_SERVER['PHP_AUTH_USER'] != 'alibaba') || ($_SERVER['PHP_AUTH_PW'] != 'alibaba') )
     {
      header("WWW-authenticate: basic realm='Admin'");
      header("HTTP/1.0 401 Unauthorized")
      exit;
     }
     }
     }
    }
  • AH_PRODUCTION lets you test wheter you are running the site locally or in production.

    _main.php :
    if ( AH_PRODUCTION )
    {
     setlocale(LC_TIME, 'fr_FR.utf8');
     setlocale(LC_CTYPE, "fr_FR.utf8")
    }
    else
    {
     setlocale(LC_TIME, 'fr_FR');
    }