Creating Custom Modules

When you added a poll to a module and included a menu in a module, you created a custom (albeit simple) module (i.e., a user module) instead of selecting a pre-defined module. In addition to adding Tiki objects (such as polls and menus) to modules, you can use HTML or Smarty syntax as well.

 Tip

For detailed information on user modules, see Tiki Essentials.

Using HTML

You can add custom HTML to a module. This allows you to add widgets, application, and scripts from other sources. For example, you can add an automatic weather forecast (fromThe Weather Network) to a Tiki module. Simply create a new module and add the HTML code:

<div id="plemx-root"></div> 
  <a href="http://www.theweathernetwork.com">The Weather Network</a>
  <script type="text/javascript"> 

  var _plm = _plm || [];
  _plm.push(['_btn', 94593]); 
  _plm.push(['_loc','usny0996']);
  _plm.push(['location', document.location.host ]);
   (function(d,e,i) {
  if (d.getElementById(i)) return;
  var px = d.createElement(e);
  px.type = 'text/javascript';
  px.async = true;
  px.id = i;
  px.src = ('https:' == d.location.protocol ? 'https:' : 'http:') + '//widget.twnmm.com/js/btn/pelm.js?orig=en_ca';
  var s = d.getElementsByTagName('script')[0];

  var py = d.createElement('link');
  py.rel = 'stylesheet'
  py.href = ('https:' == d.location.protocol ? 'https:' : 'http:') + '//widget.twnmm.com/styles/btn/styles.css'

  s.parentNode.insertBefore(px, s);
  s.parentNode.insertBefore(py, s);
})(document, 'script', 'plmxbtn');</script>

Use the Custom Modules tab on the Admin: Modules page to create a new, custom module:
Create new user  module.

  1. In the Data area, paste the code from the widget.
  2. In the Parse Using field, select None.
  3. Click Create. Tiki prompts for confirmation, then saves the information and displays the newly created module in the Custom Modules list. Your custom module:
    User modules.
  4. To display the module in a column, select Actions > Assign. The Assign/Edit modules tab appears.
  5. Complete the fields as shown in the Adding Modules section.
    The module includes the weather report for New York, USA:
    Current weather module

Including Smarty

You can include Smarty syntax in your modules to do all sorts of neat things, such as displaying Tiki variables. For example, using this code:

Hello {if $user}{$user}{else}anonymous visitor{/if}!


will create a module that:

  • If the user is logged in, the module will show:
    Hello the user's name!
  • If the user is not logged in, the module will show:
    Hello anonymous visitor!

 Warning

If you include Smarty coding in you templates, it must validate properly, or your pages will not display.

Refer to this troubleshooting tip if Tiki displays a message indicating a Fatal Smarty error.

<HR>

Copyright

This guide is based on content originally published by KeyContent.org.

This guide is Copyright (C) 2007-2013, 2019 by Rick Sapir and others under a Creative Commons Attribution-Share Alike 4.0 License. Some rights reserved.

Essentially, you are are free:

Image

to Share — to copy, distribute and transmit the work
Image

to Remix — to adapt the work


Under the following conditions:

Image
Attribution. You must attribute the work to me, as the original licencor, but not in any way that suggests that I endorse you or your use of the work.
Fair attribution includes a return link to http://tikiforsmarties.com (for online use) and mention of primary author (Rick Sapir) and original publisher (KeyContent.org).
Image

Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license.


Please read http://creativecommons.org/licenses/by-sa/3.0/legalcode for the full license.

Tiki®, TikiWiki® and the Tiki logo are registered trademarks of the Tiki Software Community Association, used with permission.