Jump to:

23373 Posts in 18175 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » widgets with page translations

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

Page: 1
Go to End
Author Topic: 552 Views
  • Fruit
    Avatar
    Community Member
    4 Posts

    widgets with page translations Link to this post

    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.

  • Fruit
    Avatar
    Community Member
    4 Posts

    Re: widgets with page translations Link to this post

    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

    552 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.