Search

Hello people,

I am quite baffled by something that is supposedly very easy to do. I have 2 sections: Articles and Categories. Quite obviously, articles are sorted by category and I do that by using a Select Box Link in the Articles section.

Now my problem is that I would like to display all categories in a single page, and for each category only display a fixed amount of articles (sorted by date). The sorting and limiting provided by the Data Source does not really help, as it sorts articles only by date, so if I limit the articles to, say, only 5 entries per page, I end up with only 5 articles in total (all of which might be from the same category depending on the date they were created).

I understand that I could work around this for example by creating a section and data source per category, but that is not very practical and "future-ready" as I might add more categories in the future and I don't want to mess around with data sources all the time, so I would prefer a more elegant and automated solution.

I'm probably stuck in some logical loophole, and I'd really appreciate some more expert guidance.

Thanks a lot for your time :)

I'm probably stuck in some logical loophole, and I'd really appreciate some more expert guidance.

Nope, stuff like that is definitely not easy in Symphony. I needed to do almost exactly the same for a project recently, and after some research and trying different approaches, I ended up with a custom datasource using Nick's SymQL extension (thanks a lot, Nick).

If you're not afraid of getting your hands dirty with a little PHP and MySQL, here's a Gist for you with my custom datasource.

If someone else has a better/faster/more elegant solution, please let us know.

Thanks a lot, I'll look into that, although I'm not very expert in either PHP or MySQL. I'd never thought it would be so hard to do such a simple task with Symphony.

@finferflu, do you have an sample XML data for us to look at? There has to be a way this could be tackled with XSLT.

@finferflu, do you have an sample XML data for us to look at? There has to be a way this could be tackled with XSLT.

I think the problem with the XSLT approach is that it requires you to definitely have enough entries returned from the datasource to cover each category, and when you don't know how old the latest entry from each category is, that becomes a problem. To how many entries do you limit the datasource?

I think the problem with the XSLT approach is that it requires you to definitely have enough entries returned from the datasource to cover each category, and when you don't know how old the latest entry from each category is, that becomes a problem.

Exactly. You would have to fetch ALL entries for each category to make sure there will be no nasty side effects under some circumstances.

Thanks a lot, I'll look into that, although I'm not very expert in either PHP or MySQL.

The requirement you described above sounds almost exactly like mine, so I guess you can use my datasource as is and just change the parameters (section names, fields, etc.).

Let me know if you need further help with the customization.

Ah! didn't think of the returning of all entries.

I decided to tackle this problem as something an extension could solve. Check it out: https://github.com/tachyondecay/ds_multiplier The README contains steps for achieving the use case from this topic.

It’s a little rough around the interface edges—I’m not all that familiar with how the duplicators work, so the checkbox in the DS editor that makes all the magic happen doesn’t actually show up until one has added the filter and reloaded the page! But it works and requires no knowledge of how to create custom data sources or SQL. :)

Wow, that was an amazing feedback! Thanks a lot everybody for your help, I am going to try these solutions and see which one fits me better. Hopefully things like this may be easier to do in future versions of Symphony.

Thanks again :)

@tachyondecay I've tested your extension first as it seems the most immediate solution for me, but I am unable to make it work. I have followed your example tutorial, but I get this in the resulting page:

<articles>
  <section id="1" handle="articles">Articles</section>
  <error>No records found.</error>
  <error>No records found.</error>
  <error>No records found.</error>
  <error>No records found.</error>
</articles>

To be sure, ds-categories.system-id parameters are output as follows:

<ds-categories.system-id>
  <item handle="4">4</item>
  <item handle="3">3</item>
  <item handle="2">2</item>
  <item handle="1">1</item>
</ds-categories.system-id>

Am I missing something? Thank you.

EDIT: Actually, I managed to make it work by changing the output parameters of the Categories data source from ds-categories.system-id to ds-categories.category-name, and then filtering the Articles's categories by {$ds-categories.category-name}. It's a bit confusing as the Symphony documentation indicates (and here) that Select Box Links maintain their associations through system ID rather than other fields. I guess that happens at a lower level now, but it wasn't the case in earlier versions.

Anyway, thank you: this extension has provided an elegant and reliable solution for me :)

That’s weird. I tested it on a Symphony 2.3 install, and it worked fine with the system ID/{$ds-categories.system-id} filter.

Maybe someone more knowledgeable in the ways of Symphony’s internals might be able to shed some light on the discrepancy. For now, though, I’m glad you found a way to get it working. :D

this extension has provided an elegant and reliable solution for me :)

Damn, why wasn't this available when I needed it... Nevermind, at least I learned how to create custom datasources... ;)

Yeah, I consider myself very lucky that somebody just wrote an ad-hoc extension just for me :)

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