Search

I want to add my own page parameters to use in DS filtering. I've tried with:

<xsl:param name="in-english" select="'yes'" />

The code is added right at the beginning, after the opening <xsl:stylesheet> in my master.xsl. But the param is not added to the page parameters and is not available for DS filtering either.

What am I doing wrong?

I think for a param to be used in DS filters it needs to be in the 'param pool' (the params you see on the ?debug screen), which is a subset of all the params available to xsl during processing. Creating a global param in your xsl doesn't put it in the pool; I think you need to add it via a datasource param output.

But I could be way off, I'm still more or less asleep...

I see. What I want to do is this:

I've got a bilingual site, swedish as main language, english as seconde. In my article and blog sections I've got a checkbox for "In english".

The root (www.domain.com) as well as domain.com/blog and /articles will be in swedish.

English root will be at domain.com/in-english, having /in-english/blog and /in-english/articles as subpages.

I want to use the same DS regardless if it's a swedish or english page calling it, using a filter to get the content of the correct language.

I can't find a way to do this.

Having a select-box instead, with "In-english" and "In-swedish" as values makes it possible to filter by the $root-page parameter, but only as long as the user is on /in-english or any of the subpages. For the swedish part of the site, the $root-page differs from page to page.

Ideally, I would like to filter by $root-page, when it's "in-english" and by a predefined value - in-swedish - when it's not.

But maybe I've to take another route? I was thinking of creating two static DS's, one to defining each language. But static DS's doesn't have parameter output as an option, so that doesn't seem to work either.

Any ideas?

If you change it to a select box, with values of "In Swedish" and "In English," you could, I believe, just do this:

{$lang:in-swedish}

Then if your pages are set up to accept a page param called lang, this tells the DS to filter by the $lang param (which would be in-english), and if that's not provided, then default to filter by in-swedish

I found a solution. I created the section Boolean, with just a text field. I then created two entries in the Boolean section: "yes" and "no".

Then, in DS editior, I created the DS "boolean: yes", which fetches entries from the boolean section, filters by value "yes" and outputs that value as a param. That DS is then attached to all english pages.

On the english pages, I've now the param $ds-boolean-yes with value 'yes'.

In the DS's for articles and blogs, I can now filter on the "In english" checkbox, using enumeration, like this:

{$ds-boolean-yes:no}

That means, on pages where $ds-boolean-yes is set, filter by it's value. On other pages, filter for entries where the checkbox is not checked.

I'm assuming your data structure has both swedish and english versions of the content in the same entry.

If this is so, then I don't think there is a way to use a single data source to achieve your goal. A datasource selects the fields it will output, and a ds filter can only select the entries to pull those fields from. You could pull both versions into your xsl transform, then just use a template to only output what you want, but I don't think thats necessary.

If 'in-english' is a Symphony page, then you will still only need to load 1 datasource per page: one that selects the english content fields for the /in-english/ Symphony page, and others that select swedish content fields for the /blog and /articles page. In this case, you won't need to use filters in regards to language.

No. There is not the same content in to different languages. There will be some english, some swedish blog content. But I want to keep them in the same section, to have fewer sections in the backend. The checkbox is used to tell the system wether a specific entry is in english or swedish, and with help of the "boolean: yes" DS (described above) attached to all english pages, I can use the same datasource for both languages.

@czheng: That was the route I wanted to go, but I couldn't find a way to create that page parameter.

(Even tough me plan was to keep the checkbox and create a In english parameter that would take the value of "yes" on the english pages and not be set on the swedish).

I'm not sure I'm following along, but the title struck out to me as I recently wondered how to add a page parameter via an event. You'll need to get your hands dirty with a custom event, but this extract shows you how I accomplished adding a page parameter.

    public function getSubscribedDelegates() {
        return array(
            array(
                'page'      => '/frontend/',
                'delegate'  => 'FrontendParamsResolve',
                'callback'  => 'addParam'
            )
        );
    }

    public function addParam($context) {
        if($id = $this->getEntryIDFromElement('username', $this->getEmail())) {
            $context = $context['params']['member-id'] = $id;
        }
    }

Thanks, Lewis. The whole time, I realized that my solution really was only a work-around. Will give your suggestions a go later today.

You could have a form that asks for language preference, something like:

Event specifics##

public function load()
    {           
        if(!isset($_POST['action']['set-lang'])) {
            return $this->__trigger();
        }
    }

public function __trigger() {
        $this->_Parent->Cookie->set('lang', $_POST['lang']);
}

Extension Driver specifics

public function getSubscribedDelegates() {
    return array(
        array(
            'page'      => '/frontend/',
            'delegate'  => 'FrontendParamsResolve',
            'callback'  => 'addParam'
        )
    );
}

public function addParam($context) {
    $context = $context['params']['lang'] = $this->_Parent->Cookie->get('lang');
}

Actually, my code above will not actually work because I think you need to initiate the Cookie class. You could do this from within the extension driver. Nonetheless, it would work just the same.

The cookie class?

The cookie class?

I honestly don't have an answer to that question. Alistair!

Lewis, I used your code above to try and create custom page parameters but it does give the desired result.

Here is part of my code:

    public function getSubscribedDelegates() {
        return array(
            array(
                'page'      => '/frontend/',
                'delegate'  => 'FrontendParamsResolve',
                'callback'  => 'addParam'
            )
        );
    }

    public function addParam($context) {
        $sets = $this->getSets();

        foreach ($sets as $set) {
            if(!$this->isPageSelected($context['page_data']['id'], $set['id'])) {
                $parameters = $this->getParameters($set_id);
                foreach ($parameters as $parameter) {
                    $context['params'][$parameter['param']] = $parameter['value'];
                }
            }
        }
    }

The parameters do not show up at the debug screen, but when I read $context the parameters appear as such: [delegate] => FrontendPageResolved [params] => Array ( [param1] => value1 [param2] => 2 [test] => test ). What am I doing wrong? I am writing an extension to add global parameters which is almost finished, it just doesn't add the parameters yet ;)

Any ideas on what could be going wrong? If I get this line right I have finished my first s2 extension:

   $context['params'][$parameter['param']] = $parameter['value'];

carsten, are You sure that $parameter['param'] and $parameter['value'] contain valid data (not NULL, or false)? Maybe some other extension overwrites parameters generated by Your extension?

I am sure that they contain valid data, they return this into $context but I can neither access them or see them in debug mode: [delegate] => FrontendPageResolved [params] => Array ( [param1] => value1 [param2] => 2 [test] => test ). I don't think other extensions are overwriting these parameters.

I don't get this syntax (and I don't get it to work), could that be the cause of my problems?

 $context = $context['params']['lang'] = $this->_Parent->Cookie->get('lang');

Can it be that Cookie returns empty value for lang?

Also, just to be sure everything is ok on extension side, try to edit symphony/lib/toolkit/class.frontpage.php and around line 195 add var_dump($this->_param) so it looks like this:

$this->ExtensionManager->notifyMembers('FrontendParamsResolve', '/frontend/', array('params' => &$this->_param));
var_dump($this->_param);

Check if data dumped on page contains parameters generated by Your extension :).

Also add the same line after data sources are resolved (before comment about delegate):

var_dump($this->_param);
## TODO: Add delegate for adding/removing items in the params

That will show You if something overwrites Your parameters or not (they are not changed later in the process AFAIK, so it's either here or not at all).

Thanks for your help! It appears that there are no parameters generated by my extension.

The code in my previous code was just an example to illustrate that I don't understand its syntax, and data is contained in the parameter array since it is also returned when I dump $context after putting it in. I don't know where the data in $context stays though.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details