How to get the file name of "This Page" and from the other pages

How to use $thisPage and $sitePage to get information from different pages in their language. as well as Menu Titles with $sitePageTitle and Page URLs with $thisPageLink
How to get the file name of
How to get the file name of "This Page" and from the other pages

Here we have a few variables that will help us create proper links and even queries without having to worry of a fila name changes or a page name changes.

This Page

First to know the name of the file we are working on, we use the variable $thisPage. for example the url name might be contact-us in English and contactez-nous in French, but they both use the same file name:

echo $thisPage;

In this case it will return "contact" because the file name is contact.php


Site Page

To get the url name of a specific page on a specific language we use the array $sitePage, it is an sssociative where the index is the file name, and it will return the URL of the file, not the full URL

echo $sitePage['contact'];
//prints contact-us in English and contactez-nous in french

A good way of getting the current URL page name is 

echo $sitePage[$thisPage];

As mentioned earlier $sitePage['file'] doesn;t return the full url, this means that if a URL is formed as page / id / title, $sitePage['file'] will return "page". taking this blog post as an example.

The file name is article, the url page name is post

echo $sitePage['article'];
//returns post


This Page's URL

To build the whole URLwe would need:

echo $sitePage['article']."/".$ID."/".toURL($content->result(0,'title_',LANG));
//returns post/77/how-to-get-the-file-name-of-this-page-and-from-the-other-pages

But there is already a variable that does that for all kind of pages, $thisPageLink

echo $thisPageLink;
‚Äč//returns post/77/how-to-get-the-file-name-of-this-page-and-from-the-other-pages


Manu Page Titles

If we need to know the name of the link being used in the menu, we use the associative array $sitePageTitle. this will take as index the file name, similar to $sitePage

echo $sitePageTitle['contact']
//returns Contact Us in English and Contactez-Nous in French

Different from 

echo $sitePage['contact'];
//prints contact-us in English and contactez-nous in french

Both variables contain all the avalable sections of the site so print_r will return those sections in the current page language


    [index] => /
    [terms] => terms_and_conditions
    [contact] => contact-us


    [index] => Home
    [terms] => Terms and conditions
    [contact] => Contact Us


Creating Links to the Home Page

A great example of how to use this tools is when creating a link to the home page on the logo:

<a href="<?php echo $sitePage['index'];?>" class="logo" title="<?php echo BUSINESSNAME; ?>">

   <img src="<?php echo auto_version($logo); ?>" alt="<?php echo BUSINESSNAME; ?>"
   title="<?php echo BUSINESSNAME; ?>" class="img-responsive"/>



Get a Quote

Get a Quote