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


Go to End

40 Posts   3718 Views


20 August 2010 at 9:41pm Community Member, 211 Posts

Hi (hope it is the right forum for this question)

I'm using 2.4 stable

I've been tryinng to render the site tree in an XML using the recipe in the silvertsripe book (page 355 english version).

It works fine with the main site tree .

My question is how do I get to load a translated site tree or how can I know wich language I'm using

(i'm using the classic Translatable::enable();

Here is the code I'm using to get the 'main' site tree as xml :

Thanks for any advice on this .

class FlashTree extends Controller {

function xml() {
   $rootPages = DataObject::get(
      'ParentID = 0 ' /* AND ShowInMenus = 1 [to swow only visible menus from SS site tree] */

   $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

   $xml .= "<node>\n";
   foreach($rootPages as $page) {
      $xml .= $this->getNodeXML($page);
   $xml .= "</node>\n";
   return $xml;
protected function getNodeXML($page) {
   $xml = sprintf(
      "<node id=\"%s\" label=\"%s\" isBranch=\"%s\" classname=\"%s\">\n",
      ($page->Children() && $page->Children()->Count()) ? 'false' : 'true',
   if($page->Children()) {
    foreach($page->Children() as $page) {
       $xml .= $this->getNodeXML($page);
   $xml .= "</node>\n";
   return $xml;


21 August 2010 at 11:30pm Community Member, 211 Posts


I love silvertstipe but sometimes I feel stuck by things that I think have a way around.

I know I'm not a proffessional develloper and maybe the answer is easy or as been already answered but I truly tried to find the answer in the forums or doc.

If it is not possible to know wich language or site tree you're in can somebody tell me so

Thank you


23 August 2010 at 1:22am Community Member, 901 Posts

Hi there

I never used the method described in the book, but I figured out another way (template-based) to render the Site-Tree to XML with greater flexibility. You can read it up here:

I explained how it works with HTML, but you can easily change the Markup to XML... I used that approach for several Flash Sites already.

To render the Tree for another language, you could simply use the URL of the translated Site and apply the export there.

To get the locale you're currently in, use: Translatable::get_current_locale(). You can also use Translatable::set_current_locale(<locale>,<lang>) to set the locale that should be used.


24 August 2010 at 6:43am Community Member, 211 Posts

Thank you Banal for the advices

I tried you solution and this where I got

Here is my Page.php

class Page extends SiteTree {

   public static $db = array(

   public static $has_one = array(
static $extensions = array(
public function ExportContent(){
$viewer = new SSViewer(array('Export' . $this->ClassName, 'ExportPage'));
return $viewer->process($this);

class Page_Controller extends ContentController {

    * An array of actions that can be accessed via a request. Each array element should be an action name, and the
    * permissions or conditions required to allow the user to access it.
    * <code>
    * array (
    * 'action', // anyone can access this action
    * 'action' => true, // same as above
    * 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
    * 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
    * );
    * </code>
    * @var array
   public static $allowed_actions = array (
* Render the page for export
* @return string

public function export(){
return array();
   public function init() {

      // Note: you should use SS template require tags inside your templates
      // instead of putting Requirements calls here. However these are
      // included so that our older themes still work


Here is my template/export/

<% if Children %>
<div class="children">
<% control Children %>
<% end_control %>
<% end_if %>

Here is my template/export/

<!DOCTYPE html>

<html lang="en">
      <% base_tag %>
      <title><% if MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> &raquo; $SiteConfig.Title</title>
      <link rel="shortcut icon" href="/favicon.ico" />
      <% require themedCSS(layout) %>
      <% require themedCSS(typography) %>
      <% require themedCSS(form) %>
      <!--[if IE 6]>
         <style type="text/css">
          @import url(themes/blackcandy/css/ie6.css);
   <div id="BgContainer">
      <div id="Container">
         <div id="Header">

<div id="HTMLSiteTree">
<% control Menu(1) %>
<% end_control %>
      <div id="Footer">
         <% include Footer %>

Now if i do like in you post I do get a page but it is the same page (the regular page linked to Page .ss) that I usally get and I can't see my <div id="HTMLSiteTree"> with you control inside.

I did flush and publish the pages

I think I missed something.

My ohter question is where does the Translatable::get_current_locale() line .
In _config.php

can you help me ?

Thanks again for your advice.


24 August 2010 at 6:17pm Community Member, 901 Posts

Hi there. This looks all fine. Except one tiny bit: You should put directly into the templates Folder, not in template/export/

The Translatable set_current_locale and get_current_locale aren't needed.. you could use get_current_locale to get the language the user is in, or you can switch locale manually using set_current_locale (for example in the init method of the controller) when some action is triggered.


24 August 2010 at 6:41pm Community Member, 211 Posts


Thank you for your answer.

Will try that asap and get back to you .

About the get_current_locale issue it might help me for something else .

I have in a template some tabbed content (a Jquery tool I'm using).

I was about to use a different template for each of my language to change the the tabs text .

But maybe there is something to do with get_current_locale and some conditional statement ?

Have you any idea about that (old post, docs, tutorial)?

Thanks a lot

(below the template code used for those tabs, the variables like $TextProduct are some HTML fields in the cms)


<ul class="tabs" id="Tabs">
   <li><a href="#">Le Soins</a></li>
   <li><a href="#">Le Bon Geste</a></li>
   <li><a href="#">Le Secret Evidens</a></li>

<!-- tab "panes" -->
<div class="panes" id="Panes" >

<!-- This JavaScript snippet activates those tabs -->
$(function() {
   $("ul.tabs").tabs("div.panes > div");


<!-- <script>
;(function($) {
$(document).ready(function() {
alert('jQuery is loaded!');

</script> -->


24 August 2010 at 8:51pm Community Member, 211 Posts

Hi Banal

I tried to put directly in my template folder.

I get a result but it is giving me the site tree with all the content of the pages (example sinpset below)

But my site is not full flash.

What I need is to get only the site tree with "page name" and "URL"

<h1>TIITLE 1</h1>
<p><span class="titrecouleur">text</span> <span class="italiquecouleur">text</span></p>

something like this

<node id="24" label="Home" isBranch="true" classname="Page">
<node id="31" label="SAHOS BY EVIDENS" isBranch="false" classname="RedirectorPage">
<node id="36" label="Saho Purifiant" isBranch="true" classname="EditorialPage3">
<node id="37" label="Saho Nourrissant" isBranch="true" classname="EditorialPage3">
<node id="38" label="Saho Perfection" isBranch="true" classname="Page">
<node id="39" label="Saho Eclat" isBranch="true" classname="Page">
<node id="40" label="Saho sur mesure" isBranch="true" classname="EditorialP


Maybe I misunderstood something again.
What I think is that I have to set my XML template in my template

Am I right ?

this is what I have wrriten in my

<?xml version="1.0" encoding="UTF-8"?>
<% control Menu(1) %>
<% end_control %>

Thanks again for your help


24 August 2010 at 9:04pm Community Member, 901 Posts

Yes exactly. You can easily use that method to output XML formatted as you wish.
Just change your template/export/ template to something like this:

<node id="$ID" label="$Title" isBranch="true" classname="$ClassName"></node>
<% control Children %>
<% end_control %>

Don't know what the "isBranch" is exactly? You could also build a nested site-tree easily...

Go to Top