In our quest to review all the PHP code in the index.php file of the Beez2 template, we come to the following code:

$doc->addScript($this->baseurl.'/templates/'.$this->template.'/javascript/md_stylechanger.js', 'text/javascript', true);

In this article, we will focus on $this->baseurl

 

What is $this->baseurl?

We can view the content of $this->baseurl by adjusting our PHP code as follows:

$doc->addScript($this->baseurl.'/templates/'.$this->template.'/javascript/md_stylechanger.js', 'text/javascript', true);
echo "<pre>" . $this->baseurl . "</pre>"; die();

The result of this code prints the following to the screen:

/joomla25

When we installed Joomla 2.5, we installed it at http://domain.com/joomla25. $this->baseurl contains the location within your domain that Joomla is installed at. Knowing the path to Joomla is useful because you can use it to reference other files and build the URLs to your javascript and css files.

 

Example usage of $this->baseurl

If you didn't want to hard code a link to your homepage (just in case you change the URL), you can use $this->baseurl to print it instead. In this tutorial, we'll walk you through the steps for using $this->baseurl to set the logo in the Beez2 template to link to your homepage.

To use $this->baseurl in a Joomla 2.5 Template:

  1. Use your favorite file editor and open for edit:

    templates/beez_20/index.php

  2. At line 118, replace the following line:

    <img src="/support/<?php echo $this->baseurl ?>/<?php echo htmlspecialchars($logo); ?>"  alt="<?php echo htmlspecialchars($templateparams->get('sitetitle'));?>" />

    with...

    <a href="/support/<? echo $this->baseurl; ?>"><img src="/support/<?php echo $this->baseurl ?>/<?php echo htmlspecialchars($logo); ?>"  alt="<?php echo htmlspecialchars($templateparams->get('sitetitle'));?>" /></a>

    What we did was put the Joomla site's logo image within an <a></a> tag. Instead of typing the url as:

    <a href="http://domain.com"></a>

    ... we used the following:

    <a href="/support/<? echo $this->baseurl; ?>"></a>

  3. Save the file and visit your website to see the changes.

It's that easy! Anywhere within a Joomla 2.5 template, you can use $this->baseurl to print the URL to your Joomla site.

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?

Comments

Post a comment
n/a Points
2014-04-30 12:02 pm

I developing a hybrid app for my website https://taxisocial.net, but there area some url that does not work.

Baseurl variable is empty. And I used JURI::baseurl() function, it works but some urls does not have the "/"

 

Staff
9,521 Points
2014-04-30 2:47 pm
Hello miguel, and thank you for your comment.

Are you encountering issues with your URLs just on mobile, or on all platforms? What is an example of one of the URLs that is currently having an issue? I took a look through a bunch of links on the site and was unable to recreate any problems.

- Jacob
n/a Points
2014-07-14 12:58 am

HI miguel,

I am new in joomla and i want the URL when user is not logged in joomla.

so, how can i get current URL of browser with out logged in joomla.

e.g. user type submit article url then logged in, user must redirect to the submit article page.

how can i fix this issue.

please help me.

Staff
7,372 Points
2014-07-14 10:25 am
There are a few different options to do so location on this post in the Joomla forums.

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.

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!