Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba

Get By Link and Unpublish page


Go to End
Reply


1225 Views

Avatar
Cristian

Community Member, 8 Posts

12 March 2010 at 3:33pm

Hi Everyone,

I'm working with the 2.4 svn build, and use the get_by_link function, it works really well.

But in this particular case it wont work:

I try to get a page that is currently in saved mode but not publish. and the get_by_link can't see it, I put the cache to false but same result.

I also try the switching the stage mode and no succes here is my method:

	public function LocalizePage($url) {																																
		$page = SiteTree::get_by_link($url, false);							
							
		if($page && ($page->Locale != Translatable::get_current_locale())) {
			$page = $page->getTranslation(Translatable::get_current_locale());

			return $page->Link();
		} else {

			$oldMode = Versioned::get_reading_mode();
			Versioned::reading_stage('Stage');
			$page = SiteTree::get_by_link($url, false);		
			Versioned::set_reading_mode($oldMode);

			if($page && ($page->Locale != Translatable::get_current_locale())) {
				$page = $page->getTranslation(Translatable::get_current_locale());

				return $page->Link();				
			}		
		}
		
		return $url;
	}

thanks
Cristian