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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

widgets with page translations


Go to End


2 Posts   1018 Views

Avatar
Fruit

Community Member, 4 Posts

23 June 2011 at 4:04am

When using the code below for a widget in a site with translations,

the widget for a page in one language will be shared across all translated pages - this means that when on a translated page the widget possibly links to a page not in the same locale

is there any known fix for this?

class LinkWidget extends Widget
{
static $db = array(
'LinkPage' => 'Text',
);

static $has_one = array(
'LinkToSiteTree' => 'SiteTree',
);
function LinkToPage(){
$strURL = '';
if (isset($this->LinkToSiteTreeID) && is_numeric($this->LinkToSiteTreeID)){
$page = DataObject::get_by_id('SiteTree',$this->LinkToSiteTreeID);
if ($page){
$strURL = $this->BaseHref().$page->RelativeLink();
}
}
return $strURL;
}
}

//template

<a href="{$LinkToPage}"></a>

However each widget will link to the page one page in one language. for example, if I had a site with 2 translation (English and German) if i add a widget to a English page linking it to another English page, then the German translation of this page will also have that widget with the same image as the engliah page and it will link to the english page instead of the translated German page.

Avatar
Fruit

Community Member, 4 Posts

29 June 2011 at 2:54am

Edited: 29/06/2011 4:50am

Let me rephrase this.

Is there anyway to have different widgets on each translation of a page?

Rarther than each translation of a page to have the same widgets no matter which language it is.

Thanks