Search

Guys,

Edit Re-reading this post seems very long and confusing. If my problem is not clear from this post, tell me, and I’ll try and rephrase it… gets coffee

I have the following structure:

category/[subcategory/sub-subcategory/]product

A product has a simple Selectbox Link to a Category section, no nested categories extension etc. is used. A Category instance can have a parent which is a link to itself (the Category section).

sub-categories are therefore optional: you could have /friends/animals/cats/garfield or /friends/nermal (categories and names are fictional ;) )

I have a DS that filters ‘featured’ Products (checkbox). On a Overview page (top level category) I’d like to list all ‘featured products’.

So: /friends could list both Garfield and Nermal if they are featured

No problem adding a ‘featured produtcs’ DS to the /friends/ page, but: I need to construct the (absolute) URL of each product to be able to deeplink. I have the product’s handle (e.g. garfield) and its category (e.g. cats) but I need to be able to figure out its parent-categories (e.g. http://foo.com/friends/animals/cats/garfield) (as you see I’m missing the `../friends/animals/’ categories).

What’s the best way to do this? Am I missing something obvious?

The only thing I can think of at the moment is getting a DS with all(!) categories and all(!) products and recursively looping through them all, checking if the current category has parents. This seems terribly unefficient and slow…

Is there a better way to have some get_absolute_url() function that returns the URL representing the current object?

It should be possible to get Symphony to (recursively) return all parent categories of a category, right?

Your best bet is probably a custom DS. Although maybe there’s scope here for an extension that can do this sort of thing…

Thanks Craig

How exactly do you think such a custom DS would work? (I would think this is the sort of thing that would be built-in in Symphony)

I would think this is the sort of thing that would be built-in in Symphony

Not a trivial matter, because how you define parent/child relationships (or any relationships, for that matter) is not predetermined by the system. You might have multiple select box links in each section and only one of them is, in your mind, the “parent”. You know?

Much better IMO to delegate something like this to a specific extension that can be used to root out an entry’s ancestors based on some configurable relationship schema.

How exactly do you think such a custom DS would work?

Hm. I’d probably take the existing Products DS, and for each entry run a recursive search on the DB for its category’s parents until there are no more. So you’d end up with something like:

<entry>
    <name>Garfield</name>
    <category>
        <name>Cats</name>
        <parent>
            <name>Animals</name>
            <parent>
                <name>Life Forms</name>
            </parent>
        </parent>
    </category>
</entry>

Maybe that’s a little convoluted, but you get the point. I’m sure one of the more experienced programmers around here has a better idea :)

Craig,

Thanks for your comment. I understand the issues. I’m coming from a Django background where there’s a convention to create a get_absolute_url method on your model that constructs and returns your instance’s URL (Django doc. on get_absolute_url()). It’s purely ‘convention over configuration’, which I believe is in line with Symphony’s philosophy, and works well…

Maybe there could be an option to add such a custom method to Symphony ‘models’ (Sections). Or would this be the ‘custom DS’ you speak of? (I’m not really familiar yet with the concept of custom DS’es)

Anyway, my first thoughts on how to handle this was similar to yours: recursively run through categories to build a tree.

I am very interested in the thoughts of other awesome Symphony hackers (please take the bait :) )

Maybe there could be an option to add such a custom method to Symphony ‘models’

Well I’m arguing that this type of functionality could be provided by an extension. Don’t think we’d see it in the core because in my mind it still probably makes too many assumptions about your project and your content.

The extension could be a field type based on Rowan’s Reflection Field. That might work really nicely.

Craig that’s actually what I meant: adding custom methods on sections through an extension. The Reflection field crossed my mind too…

I know of custom ‘events’ but would it be possible to add some extra functionality to a sections’s instance through some ‘custom method’? this way I could add some XML element to a node set with e.g. The item’s URL… Adding a reflection field would probably do half of what I need in this instance (adding a field based on some other field’s values), I would need to run extra logic to, in this case, figure out the item’s parent categories.

Anyway, thanks for your thoughts. I can’t imagine no one else ran into this… Maybe I should (just) use the ‘nested categories’ extension. Would that provide the XML (parents) I need?

Maybe I should (just) use the ‘nested categories’ extension. Would that provide the XML (parents) I need?

As far as I know, it doesn’t. I’m facing the same problem as you and I started writing some notes for a future extension that provides XML trees of entries. It seems like a tough challenge, though. :)

eKoeS: thanks. It would be great if someone started building something like that. To me it does not seem too difficult: I would simply need to have some (extra?) element (‘path’?) in the Entry’s XML that would be filled with the item’s ancestors/parent-categories. Obviously it would need some convention (or configuration ;) ) as to what elements (‘parent’ category?, ‘parent’ page?, etc.) to base it on.

At the moment I’m running into another related issue with optional categories in the URL/Path. How can I use 1 Page and either show an overview of items or an item detail view when the categories are optional? I.e. the URL params could be /category/sub-category/item or /category/item?

In the first case: /category/sub-category/ should show an overview page, but (the second example) /category/item should show a detail view of item (‘item’ being an entry, not a category).

I would love to be able to do this but I cannot see how.

When I figure out an entry’s path the most I can do at the moment is use a different Symphony Page I guess…

@davidhund Maybe the URL Segments extension can help. If you have some naming convention in your URL segments/parameters, you could build some logic around it in a custom datasource to get either a list of entries or a single entry.

And if you have items with multiple categories it would be better to have a separate page for the single view to avoid duplicate content penalties from search engines.

Been thinking about this very recently and am attempting to use Breadcrumb_field and Reflection_field to achieve the desired URL structure.. just trying to get the reflection field to accept the Breadcrumb Fields "current" mode and then use the refection value as output parameter for the page filtering..

Does this sound like it would work or am I barking up the wrong tree.. we could then hide the reflection field from view in the section and filter on it in the Datasource no?

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