Get alias from a page URL

This is more of a update post for a UDT i used in guest post Articles on Arvixe Blog that is CMSMS Hosting Partner.
In case you missed those articles  you will find these articles as "How to Add Content Summary for Search Results" and "Creating a Multilingual CMSMS Site Using MleCMS Module".

As there were some changes since CMSMS 1.10.x series, there is a good chance that the UDT mentioned in those articles will no longer work and the method used in the "How to Add Content Summary for Search Results" wasn't very reliable, as there is a good chance that you might have multiple pages with same Title.

To create the UDT go to "Extensions » User Defined Tags" and add a UDT, name it for example set_alias.
And this is the updated UDT code.

/** Get page alias from url
 * @params string $params['url']
 */

$cntnt = cmsms()->GetContentOperations();

foreach ($cntnt->GetAllContent() as $page) {
    if ($page->GetURL() == $params['url']) {
        $return = $page->Alias();
        break;
    }
}

if(!empty($params['assign'])){
        $smarty->assign(trim($params['assign']), $return);
} else {
        return $return;
}

What is changed here? Well not much. The method we are using now is to retrive a page Alias from page URL instead of Title.
So to use the UDT simply use parameter url=, you can also use assign= to assign the UDT to a variable. 

{set_alias url='http://www.your-site.com/some-page'}

As the idea of this UDT was to retrieve page alias in Search module results you would use it in Search module as following.

{set_alias url=$entry->url assign='get_alias'}

Comments