This tutorial series, Joomla 3 component development, is currently in progress...

In our last tutorial, we showed you how to create the default view for the component that we are creating. The component's name is com_helloworld, so the default view is helloworld - this is just how the "default view" works.

In this tutorial, we are going to show you how to add a new view. This new view we will call "Howdy Friends".

To create a new view:

  1. Create the view's folder: /components/helloworld/views/howdyfriends

    Because we are referring to this new view as "Howdy Friends", we will name this view howdyfriends.
  2. Create the HTML version of the view: /components/helloworld/views/howdyfriends/view.html.php

    <?php
    // No direct access to this file
    defined('_JEXEC') or die('Restricted access');
     
    // import Joomla view library
    jimport('joomla.application.component.view');
     
    /**
     * HTML View class for the HowdyFriends view
     */
    class HelloWorldViewHowdyFriends extends JViewLegacy
    {
            // Overwriting JView display method
            function display($tpl = null)
            {
                    // Assign data to the view
                    $this->msg = 'Howdy Friends, welcome to component development!';
     
                    // Display the view
                    parent::display($tpl);
            }
    }
  3. Create the "templates" folder: /components/helloworld/views/howdyfriends/tmpl
  4. Create the default template file: /components/helloworld/views/howdyfriends/tmpl/default.php
    <?php
    // No direct access to this file
    defined('_JEXEC') or die('Restricted access');
    ?>
    <h1><?php echo $this->msg; ?></h1>

How to test your new view

Now that the hard part is over, let's test our view! It can be accessed using the following url:

http://example.com/index.php?option=com_helloworld&view=howdyfriends

The URL above was created by defining the component we want to run - com_helloworld, and the component's view we want to run - howdyfriends.

If you're following along with our tutorial, when testing your new view, it should look similar to the image to the right:

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

News / Announcements

WordPress wp-login.php brute force attack
Updated 2014-07-17 06:43 pm EST
Hits: 201658

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Joomla Community Google+ Hangout #3

June 3rd, 2014

Thank you @RustyJoomla for letting me speak on the Joomla Community Google+ Hangout!

Click here to watch!

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!