Search

Hey guys,

Been working on projects outside of Symphony for a number of months and I'm now a little rusty, so I was wondering if someone could help me wrap my head around a problem with URLs.

I'm converting a WordPress site to Symphony (hurray!), and part of that means moving over WordPress' traditional page/posts sections and retaining the URL structure.

I want to be able to have both page/posts urls work from the base url, for example:

  • http://example.com/page/
  • http://example.com/this-is-a-blog-post/

I have:

  • 2 sections: articles and pages
  • 1 page set as index with a {$title} param
  • 2 datasources filtering on the {$title} for each section
  • 1 datasource getting latest articles, but only when {$title} isn't present using Nils' technique

This actually works, but the problem is 404s don't. If I set the datasources to redirect to 404 on empty this causes a 404 to constantly occur because if a post is found, a page is not showing a 404 page and vice-versa.

I tried another setup using URL Router, but could only get this to work for the rule at the top of the list. It wouldn't cascade down the rules if a match wasn't found (I'm probably misusing the extension).

I get the feeling this is a rather simple problem, but I can't quite see the solution.

Any ideas? Thanks!

Okay, so I think I may have solved this by combining URL Router and Union Datasource, so I'll try and explain what I've done in case anyone else has this issue.

I separated the list and detail pages for simplicity. If theres a better way to do this please let me know!

Create sections

Created 2 sections, Articles and Pages. Very similar in set-up. For this example they just have Title and Content fields.

Setting up homepage

Created a data source called Latest Articles set to filter the 5 most recent articles from the Articles section.

Created a page called Home. Set page type as index so its used as the homepage. Attached this data source to the Home page that was just created.

Setting up single page

Created a data source called Single - Article with the Articles section as the source. Filter results by title using {$title} param. Set '$title' as required URL parameter. Add 'title' and 'description' as XML output.

Created a data source called Single - Page with the Pages section as the source. Filter results by title using {$title} param. Set '$title' as required URL parameter. Add 'title' and 'description' as XML output.

Created a data source called Single with the Union Datasource as the source. Choose the Single - Article and Single - Page as data sources to combine. Set '$title' as required URL parameter. Set to Redirect to 404 when no results.

Created a page called Single. URL handle is 'single'. Set URL parameters to 'title'. Attach Single data source.

Setup route

Go to Blueprints > URL Routes from the URL Router extension.

Create new route. Set From as ':title'. Set To as 'single/:title'.

That should be it! For reference XML / XSLT should look something like this:

(I tried to use Xpathr but got a 403 forbidden error when creating the gist? An error occurred in /home/xpathr/public_html/extensions/xpathr/lib/class.xpathr.php around line 250).

Hopefully that'll help someone in the future, if theres a better way to go about this let me know, thanks!

Just wondering, what happens if a (fake-)page and an article have the same handle?

Just tried this out creating an entry in both Articles and Pages with matching handles, and the Pages entry is shown.

Not sure why the Pages section is preferred over the Articles section. I tried creating the article first, then the page in case its a date thing. Tried renaming the datasources if it was alphabetical somehow, as well as swapping the order in Union Datasource but no change.

Not really an issue as this is the functionality I'd like, and I think WordPress worked in this way too. There's many more Articles than there are Pages and its highly unlikely they'll ever share the same handles (Pages handles being 'about-us' etc).

I guess if someone needs to have priority on one datasource over another, it would only be possible with a custom datasource?

usually this is possible even in normal datasources... however it works the other way round. you can ask a datasource to execute after another one, with the Required URL Parameter.

Is it possible to make a datasource execute after another when the first datasources returns no entries?

If so I could have the last datasource in the chain show the 404 when nothing is returned.

when the first datasources returns no entries

It would run in all cases if you set the required url parameter in the backend, after the one(s) you request. Then its up to the datasource to see when to fire a 404 or not.

However you could also add the 404 to the first datasource.

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