Hi all,
I'm writing a template which will output a link requiring a page id. I know the alias of the page that I'm trying to get to, is there a way to access the id of a page using it's alias? (not the current page)
Finding a page id from an alias - [ SOLVED ]
Finding a page id from an alias - [ SOLVED ]
Last edited by tallphil on Fri Feb 05, 2010 5:00 pm, edited 1 time in total.
Re: Finding a page id from an alias
You can make a UDT called something like 'idfromalias', containing:
You can then access it in your template with {idfromalias alias='youralias'}
Code: Select all
global $gCms;
$cntnt = $gCms->getContentOperations();
echo(GetPageIDFromAlias($cntnt->$params['alias']));
Re: Finding a page id from an alias
Sounds perfect! However, I now get the following error:
I created the UDT exactly as suggested in your post.
Code: Select all
Fatal error: Call to undefined function GetPageIDFromAlias() in /home/nanosim/public_html/lib/content.functions.php(771) : eval()'d code on line 4
Re: Finding a page id from an alias
Whoops... I got that last line a little backwards. Replace the last line with:
I have it working on my test page.
Code: Select all
echo($cntnt->GetPageIDFromAlias($params['alias']));
Last edited by Wishbone on Fri Feb 05, 2010 3:42 pm, edited 1 time in total.
Re: Finding a page id from an alias
Brilliant, worked first time! Thank you for your help, I've spent hours on this thing and I finally have it working 
FYI, I simply wanted to make the {edit} tag display a link to the edit page for a different page. In other words, on page1 have the {edit} tag go to the Admin Edit page for page2.
This is my (now working) solution:
Out of interest, how would I go about putting this into a nice tidy UDT? Would I be able to access the {edit} module from within a UDT? Doesn't really matter as it's working now anyway.

FYI, I simply wanted to make the {edit} tag display a link to the edit page for a different page. In other words, on page1 have the {edit} tag go to the Admin Edit page for page2.
This is my (now working) solution:
Code: Select all
{capture assign='editlink'}{edit text="Edit This Different Page"}{/capture}
{capture assign='grouppage_id'}content_id={idfromalias alias='somealias'}{/capture}
{capture assign='current_id'}content_id={$content_id}{/capture}
<h3>{$editlink|replace:$current_id:$grouppage_id}</h3>
Re: Finding a page id from an alias - [ SOLVED ]
Arg! I forgot to test this whilst logged out, and the edit link disappears when not logged into the admin back end! Which makes my efforts kind of pointless. Ah well!
Re: Finding a page id from an alias - [ SOLVED ]
I guess you wouldn't want an edit link showing for users other than the admin. 

Re: Finding a page id from an alias - [ SOLVED ]
Yes the {edit} tag only works if your logged into the back end, so I've always kind of found it silly...