Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Joomla! 1.5 Templates Cookbook

You're reading from   Joomla! 1.5 Templates Cookbook Over 60 simple but incredibly effective recipes for taking control of Joomla! templates

Arrow left icon
Product type Paperback
Published in Jul 2010
Publisher Packt
ISBN-13 9781849511247
Length 236 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Toc

Table of Contents (16) Chapters Close

Joomla! 1.5 Templates Cookbook
Credits
About the Author
About the Reviewers
1. Preface
1. Joomla! Theming Basics 2. Custom Joomla! Templates FREE CHAPTER 3. Theming the Details 4. Custom Page Templates 5. Styling Joomla! for Print 6. Joomla! Admin Templates 7. Social Media and Joomla! 8. Styling Joomla! for Mobiles 9. Joomla! and JavaScript 10. Miscellaneous Joomla! Templating Joomla! Output Overrides

Customizing Joomla! articles with component template overrides


You are not limited to customizing Joomla! templates at module level; you can define component template overrides to change what is seen for Joomla! pages of a particular type. Here, we'll look at customizing article pages in Joomla!, which, by default in the rhuk_milkyway template, looks similar to this:

We'll be customizing the template to add an automatic "mention this website on Twitter" graphic alongside the icons for viewing a PDF of the page, printing the page, and sending it to a friend via e-mail.

Getting ready

As articles in Joomla! are classified as part of the content component, the default template for articles is located in the following directory: \components\com_content\views\article\tmpl\. As usual, the file that you need here is called default.php. Copy this into your template's \html\com_content\article\ directory.

You'll also need to save a Twitter icon with dimensions of 16 by 16 pixels in the \images\M_images\ directory of your Joomla! installation as twitter_button.png.

How to do it...

  1. 1. In your template's default.php, which you copied above, find the lines that read:

    <?php if ($this->params->get('show_pdf_icon')) : ?>
    <td align="right" width="100%" class="buttonheading">
    <?php echo JHTML::_('icon.pdf', $this->article, $this->params, $this->access); ?>
    </td>
    <?php endif; ?>
    
  2. 2. Below this, you can add the following code to create your Twitter button:

    <td align="right" width="100%" class="buttonheading">
    <a href="http://twitter.com?status=is reading <?php echo $this->baseurl ?>" title="Tweet this website">
    <img src="<?php echo $this->baseurl ?>/images/M_images/twitter_button.png" alt="Post this to Twitter">
    </a>
    </td>
    
  3. 3. Now visit an article page on your Joomla! website and refresh the page. You should see the changes that you just made take effect:

How it works...

Component template overrides work in a manner similar to that of module template overrides—Joomla! first looks in the currently enabled template's \html directory for a customized template for the component it is loading before resorting to the default template provided in the \components directory of your Joomla! website.

By adding ?status= followed by text to the end of the Twitter URL, that text is added to a Twitter user's status box, assuming that they're logged into their Twitter account. However, the text is not sent as a tweet to their followers until the Twitter user clicks on the Tweet button:

Note

Remember that Twitter can handle only 140 characters per message, so try and keep it short!

See also

  • Customizing Joomla!'s home page with module output override

  • Creating a new module style (chrome) in Joomla!

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image