Search

Hi everybody

I’m looking for some in depth documentation on parameters:

  1. URL Parameters
  2. Data Source Output Parameters

I’ve read the ‘Concepts’ on what parameters are used for, but I could still use some examples on how to use it ?

// Dammark

URL Parameters are explained pretty well in the Concepts section. Did you read all of it? DS Output Params are explained in Data Source Output Parameters and Data Source Chaining.

Without explaining more here, do you have specifics as to what the documentation is lacking?

Essentially URL Parameters are a way of building URLs for your website, i.e. you want an Articles page at /articles/ (create this page in Pages) but you want to also load a specific article at /articles/{article-title-here}. You would add a URL Parameter to your Articles page called “article-title”, which allows you to pass a string on the end of the URL. The value is then avaialable in the param pool as a param named $article-title. You can see all params by adding ?debug to the end of your URL.

Indeed, the documentation is very good and detailed. However, without "real life" examples it is hard for beginners to find their way.

Could someone, please, give an example on how to pass parameters to the url through a form?

I'm trying to set two parameters through the following form. The paramenters are $nazione and $tipologia.

<form id="searchForm" action="{$root}/fotografie/{$nazione}/{$tipologia}" method="GET" target="_self">
                <fieldset class="fieldset">
                    <p>Vedi le fotografie:</p>
                </fieldset>
                <fieldset class="fieldset">
                    <label class="label">Filtra per nazione:</label>
                    <select class="selectfield">
                        <option class="selectTitle">Tutte le nazioni</option>
                        <xsl:for-each select="/data/nations/entry">
                            <option class="selectOption" name="nazione" value="{@handle}"><xsl:value-of select="continente-nazione"/></option>
                        </xsl:for-each>
                    </select><br />
                </fieldset>
                <fieldset class="fieldset">
                    <label class="label">Filtra per tipologia:</label>
                    <select class="selectfield">
                        <option class="selectTitle">Tutte le tipologie</option>
                        <xsl:for-each select="/data/types/entry">
                            <option class="selectOption" name="tipologia" value="{@handle}"><xsl:value-of select="tipologia"/></option>
                        </xsl:for-each>
                    </select><br />
                </fieldset>
                <fieldset class="fieldset">
                    <input type="submit" value="filtra >>" name="" class="buttonSearch"/>
                </fieldset>
            </form>

The parameters are loaded in the XML but are not set... I have no idea how to set them and pass them on form submit. Can you give me an advice?

Thanks a lot!

I think you will need an event attached to the page that contains the form. In the event's trigger function you can get your parameters using $_GET['nazione']} and $_GET['tipologia']}. Then redirect to your desired page with those parameters in the URL.

Thanks a lot Carson. Since I don't know PHP can you help with the following:

How do I set the redirect location? Symphony wouldn't allow me to define header.

<?php
require_once(TOOLKIT.'/class.event.php');
Class eventfiltrafotografie extends Event { 
    public static function about() {
        return array(
            'name' =>'Filter by url parameters',
            'author' => array( 
                                'name' => ''                                
            ),
            'version' => '',
            'release-date' => ''
        );
    }   
    public static function documentation() {
        return '';
    }   
    public function load() {
        $nazione = $_GET['nazione'];
        $tipologia = $_GET['tipologia'];
            return $this -> __trigger();

    }
    protected function __trigger() {
        header('Location: http://www.website.com/fotografie/ '. $nazione . '/' . tipologia); 
    }
}
?>

Thanks again for your help.

Please try if this works for you:

<form id="searchForm" action="{$root}/fotografie/{$url-nazione}/{$url-tipologia}" method="GET" target="_self">

There should be no need to use a custom event.

EDIT: I don't get what you're after. Form action should just be {$root}/fotografie and then in your datasource you should filter by $url-nazione and $url-tipologia which are set by symphony automatically and don't need to be declared anywhere.

By the way, is a custom event the only way to get the parameters? Would it be possible to somehow use <xsl:variable name="..."> and (in my case) implement it with the selected option in the form field?

EDIT: Thanks! You typed faster than me... I will try this out.

It's giving me an error that the variable $url-nazione (and $url-tipologia) has not been declared. And if I use $nazione and $tipologia I think they are empty because the url returns .../fotografie//. (This is if I use POST or if I use GET, but without setting a name for the button.)

Right.

To accomplish this without custom code, this is what I'd do.

You'll end up with urls like fotografie?nazione=aaa&tipologia=bbb

You need to define these two parameters in your template (just before your first template match):

<xsl:param name="url-nazione" />
<xsl:param name="url-tipologia" />

Then you need to change your datasource to filter for $url-nazione and $url-tipologia.

Last but not least, your select must have correct names:

<select class="selectfield" name="nazione">...
<select class="selectfield" name="tipologia">...

That should work.

Thanks, Marco. I did as you suggested but I think this only works for the non-dynamic options. If I make a selection, the variables are empty. If however I filter the results without selecting anything, it returns the values of the first option, which I set manually, so the url is something like .../fotografie//?nazione=Tutte+le+nazioni&tipologia=Tutte+le+tipologie.

Maybe this is because I use three different data sources: - DS Fotografie - DS Nations - DS Types The DS Fotografie is attached to the "fotografie" page, while the other two are attached to all pages. I do this because the "filter" form is on all pages and I don't want to build the XML of every page with the DS Fotografie.

I thought that since values are the same, I can safely build the select fields with only DS Nations and DS Types. Maybe this setup is not correct?

As you said, I changed the filters for DS "Nations" and DS "Types" to url-variablename. And it filters correctly if I add the values manually in the url... But it's not setting the variables through the select fields for the dynamic options.

I'm very grateful you're helping me out.

Mmh... maybe you could try removing the name attribute from option? I'm pretty sure it's not needed, although the problem may live somewhere else.

That was the result without it. I had it there because I wasn't sure if it had to be added to the select or the option. When you confirmed "select", I deleted it from the option.

In the page settings, the URL Parameters should be url-nazione/url-tipologia or nazione/tipologia ?

In the DS Fotografie the filtering should be by url-nazione or nazione (url-tipologia and tipologia resepctively)? (DS Nations has a filter by url-nazione, and DS Types by url-tipologia)

When you submit the form, I assume you get nazione=un-valore&tipologia=un-altro-valore, is it right? If that's the case, then the problem is filtering.

With the current setup, your page should have no params.

What's the relation between your sections (I assume there's more than a section involved as you have created 3 DS)?

When I submit the form the result is nazione=&tipologia= as if the parameters are still empty... I get them populated only if I don't select any of the options and the default option gets passed - but the default option is set manually, as you can see from the form.

Yes, there are four sections:

  1. Continenti
  2. Nazioni
  3. Tipologie
  4. Fotografie

    1. Continenti has only a text input field.

    2. Nazioni has a text input field, a selct box link field to Continenti, and a reflection field to "unite" the above two fields (if you want, check this thread, where I struggled to decide on the correct setup).

    3. Tipologie has only a text input field.

    4. Fotografie: besides the upload field and a couple of text input fields, it has a select box field with dynamic values from the reflection field in the Nazioni section, and a select box field with dynamic values from the Tipologie section.

And the data sources are three, as I mentioned. I'm not sure if the problem is filtering... If I submit the form and then manually set a nation and/ or tipologia, the filtering works perfectly. It puzzles me that the "fixed" option in the select field returns its value when this is selected, while the dynamically set options - not.

PS. Strangely, your message was displayed only now. I'd have replied right away.

Aspetta...

Option values are empty then. Now that I look closer, this should be the correct code:

<xsl:for-each select="/data/types/entry">
    <option class="selectOption" value="{tipologia/@handle}"><xsl:value-of select="tipologia"/></option>
</xsl:for-each>

Indeed, I had this wrong, but unfortunately it doesn't seem to solve the problem.

The url now looks like .../fotografie//?nazione=continente-nazione%2F&tipologia=tipologia%2F

I think I have an idea that can resolve both problems (the one from this thread and the chaining I describe in the other thread).

I can setup the filter form as a form that is not actually a form. The select fields will not be fields but simple menu items with drop downs. And I can populate this dropdowns dynamically with the options, setting them as links.

Thus, imagine I have three "select field" items, if the first one lists only continents, when the user clicks on a given continent a "new" page is loaded with the continent parameter in the url. Then the second "select field" item, called nations, will populate its dropdaown based on the url parameter set by continents. And the third "select field" item doesn't have to depend on either of the other two, but can provide another parameter when the user clicks on its dropdown items. Without any button to submit, because it isn't actually a form.

This will cause multiple loadings of the page, but it would be noticeable only on the photographs page.

Do you think this could be a better approach, instead of trying to set the parameters through a form, or it's better to stick with the form?

Well that's a good progress :)

Where does that %2F come from? You said that filtering works if you populate the url manually so we must be close to the solution.

EDIT: I'd try to figure out the issue here, then you could take whatever approach you prefer ;)

I have no idea where that %2F came from :), it only made me more puzzled and tried to think of a different approach.

You are quite optimistic to call this a progress. :) Filtering by populating the url manually was never an issue, just setting those parameters through the form and passing them to the url...

Initially I thought that it would be easy to assign the selected option value to a variable that passes the parameters on form submit. Before posting here I played a lot with <xsl:variable>, but being a novice on XSLT I didn't manage to do anything.

If you can help me solve this, I'll be very grateful, because in the future I'll be able to add more options to the form to filter further. I just don't want to lose your time.

Anyway, a good guess on what's causing the problem could be that the select fields use different data sources than the DS for the section that I'm filtering.

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