Search

Hi All

I’m pretty new to Symphony. I love what I see but am finding the learning a little frustrating. I am trying to chain data sources and can’t find a working example anywhere. The tutorial documentation appears to be a bit patchy here so I’m wondering if anyone can help me by posting an example or pointing me to a tutorial.

What I want to do is to list artists and to include a list of their artworks within each artists’ listing like this:

  • Artist X
    • Artist X artwork 1
    • Artist X artwork 2
    • Artist X artwork 3
    • Artist X artwork 4
  • Artist Y
    • Artist Y artwork 1
    • Artist Y artwork 2
    • Artist Y artwork 3
    • Artist Y artwork 4
  • Artist Z
    • Artist Z artwork 1
    • Artist Z artwork 2
    • Artist Z artwork 3
    • Artist Z artwork 4

I have a section and a data source for artists and the same for artworks.

At the moment in debug mode my XML lists the artists and then the artworks, but I don’t know if the data source params are wrong of if the problem is in the page template.

If I had an example I’m sure I could get this working. Any help much appreciated and thanks to the team for developing what looks like a really promising CMS/framework.

Stuart

How are you linking the two sections together, with a Select Box Link? I’ll assume so.

So your Artists data source you should set the Output Parameters to be “System ID”. If your data source is named Articles then this should create a parameter named $ds-articles in the parameter pool (which you see when you click Params in the ?debug view) which should have a comma-list of the IDs. These IDs should be the same as the ID attributes on the <entry> elements in the XML.

To get artwork by an Artist, you want to filter your Artwork data source by this list of artist IDs. So add a filter to the Artwork data source on the “Artist” field (I presume this is a Select Box Link) using the value:

{$ds-artists}

This should then filter artwork only by the artists being displayed.

In your XSLT you iterate over each Artist entry, and then iterate over each Artwork entry, which you can look up by matching their IDs.

Concepts:

Thanks for your response Nick. I had the data sources pretty much setup as you described. When I look at the params in debug mode I see the $ds-artists parameter with the comma separated list as you describe.

With the {$ds-artists} filter in place however, my XML looses the references to the artworks. I get the list of artists followed by the navigation XML and then the following:

<artworks>
    <section id="2" handle="artwork">Artwork</section>
    <error>No records found.</error>
</artworks>

If I remove the filter on the artists data source, the XML list of artworks comes back. So somehow the artworks aren’t getting listed in the XML.

My template looks like this:

<ul>
<xsl:for-each select="artists/entry">
<li><xsl:value-of select="artist-name"/>
<xsl:for-each select="artworks/entry">
<li><xsl:value-of select="artwork-name"/></li>
</xsl:for-each>
</li>
</xsl:for-each>
</ul>

At the moment its simply showing a bulleted list of artists.

Any help much appreciated.

S

@stuartgpalmer - I don’t know if I’m reading your post properly, but try this…

Put the filter on the Artworks datasource, filter the Artists field with {$ds-artists}. Make sure to append both the artists and artworks datasources to the page.

Thanks @bzerangue. I have the DS setup to filter artworks by System ID with a value of {$ds-artists}. If I understand correctly, you are suggesting that I filter artworks by Artist with a value of {$ds-artists}. I have tried this and get the same result.

Both data sources are attached to the page.

Yes, you would filter the Artists field in the Artworks section by {$ds-artists}. What field type is the Artist field in the Artworks section? Select Box Link, Select Box or something else?

Its a select box.

Ah! That’s your problem. We are assuming you are using a Select Box Link field, which links your entries together based on IDs rather than the string value of the select box option.

If you use a Select Box, then if you change an Artist name in the future then its association with artworks will be lost. Using a Select Box Link however means that the two entries are linked by their IDs rather than by the artist name, so they will remain linked if the artist changes. It’s more robust, and allows you to use ID filtering as we’ve discussed.

Your XSLT might then look like:

<xsl:for-each select="/data/artists/entry">
        <h2><xsl:value-of select="name"/></h2>
        <ul>
            <xsl:for-each select="/data/artworks/entry[artist/item/@id = current()/@id]">
                <li><xsl:value-of select="name"/></li>
            </xsl:for-each>
        </ul>
</xsl:for-each>

It might need to be slightly different, but notice the cross-linking to the Artworks data source XML, finding entries where the artist ID matches the current artist.

Aaah. That sounds important. I have changed the field type to select box link. I have also uploaded the site so that the XML is visible to you all:

http://dev.contemporarypainters.com/gallery/?debug=xml

Yes, I know, tables. Not my preference but the quick fix.

It still looks to me like there’s a problem with the XML. I have attached images of my section structures and data sources.

Thanks again

Attachments:
Screen shot 2010-12-14 at 16.45.28.png, Screen shot 2010-12-14 at 16.45.14.png, Symphony – Sections – Artwork.png and Symphony – Sections – Artists.png

Your sections and data sources look good to me.

It still looks to me like there’s a problem with the XML

What sort of problem? Unfortunately you have to be logged-in to Symphony to see the debug view. Could you post your XML into pastie?

Here you go…

http://pastie.org/1376538

The artworks come at the end, but there are none found.

How odd. What does the XML look like if you remove the filter? And have to re-saved your Artworks to re-assign the artists with the new select bix link field?

Aaaah. I re-saved the artworks and now the XML looks better.

http://pastie.org/1376609

Is the XML OK now? If it is, the template must be wrong. This is what I have:

<xsl:for-each select="artists/entry">
        <h2><xsl:value-of select="artist-name"/></h2>
        <ul>
            <xsl:for-each select="artworks/entry[artist/item/@id = current()/@id]">
                <li><xsl:value-of select="artwork-title"/></li>
            </xsl:for-each>
        </ul>
</xsl:for-each>

The URL of the page is:

http://dev.contemporarypainters.com

Ooh, close :-)

select="artworks/entry[artist/item/@id = current()/@id]"

This is using the “context” node of your artist/entry. Because artworks/entry isn’t a child of artist/entry it won’t find any nodes. You need to make the selector look further up the document XML to find the Artworks data source. The easiest way is to specify an absolute path from the root node (/) such as:

select="/data/artworks/entry[artist/item/@id = current()/@id]"

You are an absolute legend. Thank you so much. I will take this learning into my next (bigger) project. I’d love to get this nailed as it is streets ahead of the other CMSs I have used.

Big smile at the end of the day :-)

Glad to have helped. Once you’ve got your head around data source chaining, and linking the two together using XPath, you’ve grasped the concepts that you’ll need to build most pages. Onwards and upwards!

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