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, simon_w

widgets with page translations


Reply

2 Posts   572 Views

Avatar
Fruit

23 June 2011 at 4:04am Community Member, 4 Posts

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

29 June 2011 at 2:54am (Last edited: 29 June 2011 4:50am), Community Member, 4 Posts

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