Page 1 of 1

[SOLVED] get page alias in UDT for use in admin page templat

Posted: Wed Jan 28, 2015 7:29 pm
by applejack
I need to be able to get the page alias in a UDT which is used in admin in a page template. This to use the dropdown_from_udt in ECB module for which I am trying to pull data from certain content blocks from the same page which I can do if the alias is in the UDT. It isn't possible to pass a Smarty param to the UDT. I just don't know the api syntax for doing this.

I tried using $content_obj->Alias() but it doesn't work.

Code: Select all

$result = false;
$gCms = cmsms();
$contentops = $gCms->GetContentOperations();
$content_obj = $contentops->getContentObject();

$result = Array();
    
// $alias = "events-test"; THIS WORKS
$alias = $content_obj->Alias();

if( $alias != '' ) {
    $content = $contentops->LoadContentFromAlias($alias);
    if(is_object($content)) {
        for ($i=1;$i<=2;$i++) {
            $block = 'speaker_name_' . $i;
            $result[$content->GetPropertyValue($block)] = $content->GetPropertyValue($block);
        }    
      }    
    }
return $result;

Re: How to get page alias in UDT for use in admin page templ

Posted: Wed Jan 28, 2015 10:15 pm
by chandra
The answer is simple - $content_obj does not exist in admin ;).

Re: How to get page alias in UDT for use in admin page templ

Posted: Thu Jan 29, 2015 12:43 am
by applejack
So in that case how to get the page alias or content id ?

Re: How to get page alias in UDT for use in admin page templ

Posted: Thu Jan 29, 2015 2:04 am
by rotezecke
does this work?

Code: Select all

$hm = cmsms()->GetHierarchyManager();
$node = $hm->getId();

Re: How to get page alias in UDT for use in admin page templ

Posted: Thu Jan 29, 2015 2:39 am
by applejack
Nope afraid not. Gives a blank screen when trying to edit the page.

Re: [SOLVED] get page alias in UDT for use in admin page tem

Posted: Thu Jan 29, 2015 10:54 am
by velden
Would this work:

Code: Select all

$_GET['content_id'];

Re: [SOLVED] get page alias in UDT for use in admin page tem

Posted: Thu Jan 29, 2015 11:09 am
by applejack
I solved this using GET which I tried before but had a syntax error, Doh!!

It now uses the content id not the alias.

This very useful as it enables you to cross reference content within a page. E.G. This is for a page for conference programme where they have a number of speakers which need to show their details and assign a number of speakers to different time slots which this allows me to do.

Code: Select all

$result = false;
$gCms = cmsms();
$contentops = $gCms->GetContentOperations();
$content_obj = $contentops->getContentObject();

$result = Array();
$page_id = htmlspecialchars($_GET['content_id']);

if($page_id != '') {
    $content = $contentops->LoadContentFromID($page_id);
    if(is_object($content)) {
        for ($i=1;$i<=2;$i++) {
            $block = 'speaker_name_' . $i;
            $result[$content->GetPropertyValue($block)] = $content->GetPropertyValue($block);
        }    
      }    
    }
return $result;
P.S. Thanks Velden I was in the middle of posting this when you replied.