Home Tutorials Template files II

Template files II

  previous next
February 11, 2009 by Victor    

So, let’s see how we could have the administrator choose between various templates. Start by adding the following list to the XML file.

<param name="layout" type="list" default="random" 
       label="Layout" 
       description="The layout to display the link" >
          <option value="default">Default</option>
          <option value="divmania">Div-mania</option>
          <option value="olddog">Old-dog</option>
</param>

Then you need to alter mod_ranlatest.php. We just get the layout parameter and we pass it to the getLayoutPath method.

# Get the path to the layout for the module
$layout = $params->get('layout', 'default');
require(JModuleHelper::getLayoutPath('mod_ranlatest', $layout));

Final task, we need to write the rest layouts. Here comes the best, divmania.php.

<div class="ranlatest<?php echo $params->get('stylesfx'); ?>">
  <?php if ($link[0]) : ?>
  <p><?php print $link[0] ?></p>
  <?php endif; ?>
  <a href="<?php print $link[2] ?>"><?php print $link[1] ?></a>
</div>

And for historical reasons the olddog.php.

<table class="ranlatest<?php echo $params->get('stylesfx'); ?>">
  <?php if ($link[0]) : ?>
  <tr><td>
    <?php print $link[0] ?> 
  </td></tr>
  <?php endif; ?>
  <tr><td> 
    <a href="<?php print $link[2] ?>"><?php print $link[1] ?></a>
  </td></tr>
</table>

I know, td tags could have styling as well, could not be bothered.

That’s all folks. I would be pleased to hear about your endeavour and have some feedback on how to improve this.

Finally, I would like to point you to the J.L.LeBlanc's site who has provided good stuff for Joomla newcomers. Also, to find Joomla related books you may visit Packt Publishing.

Cheers!

Add comment


Security code
Refresh