Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2024-09-01 13:55:07

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Ideas for emulating two file download categories?

I have a site for a non-profit that acts as a coordinator for several local services offices spread across the local county. I’ve built a simple internal area for them for downloads and links (e.g. to a print shop page with pre-configured products such as flags, rollups etc.). They wanted each office to have its own page of relevant files to avoid the individual offices having to piece together downloads from different pages. As some files would be relevant to all of them and some only to each individual office, I built it like this:

section (pw-protected)
– landing page – sticky article excerpt + linked article-list of sub-pages
– individual subpages – one live article per office
  – sticky article body (general text that is the same on each page)
  – live article body (text specific to local office)

file list built from files
– an “all” category
– a category for each office

a link list built from links
– an “all” category
– a category for each office 

I use the article_url_title of the subpage to get the respective file and link category relevant to them. So far so good. It works well and is fairly easy for the moderators to administer. If something changes that affects everyone, they only need update the main article or swap out a “all”-category file.

However, now they’ve expressed a desire to group downloads into things like:

  • logos
  • templates (e.g. posters, word letterheads)
  • forms
  • reports

This would be doable with two categories, but we have only one for files.

Any ideas how I could approach this? What’s occurred to me so far is:

  • prefix filenames with some kind of consistent naming scheme so they at least appear together in the download list
  • I have jcr_file_custom for adding a custom field to the file table. I could alter the plugin to make it show a select box with the type_of_file. With txp:article_custom we could use the match attribute to filter by a custom field, but we don’t have the same capability with file_download_list

Could I maybe do something with jcr_file_custom and sort and if_different?


TXP Builders – finely-crafted code, design and txp

Offline

#2 2024-09-01 15:23:47

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Re: Ideas for emulating two file download categories?

Hmmm, yeah, if it was Links then I’d say you could hijack the linksort field and sort by that, then use <txp:if_different> but files don’t have an equivalent.

I think you’re stuck with either of the two methods you outline. The custom field one will be simpler in terms of using it with <file::download_list> because you should be able to use sort="jcr_file_custom_1" and then <if::different> to spit out the headings on change.

Not ideal, but less work than splitting the filename on a delimiter and adding headers when the prefix changes.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2024-09-02 07:09:48

etc
Developer
Registered: 2010-11-11
Posts: 5,188
Website GitHub

Re: Ideas for emulating two file download categories?

It costs nothing to replace IN with LIKE in category query and allow for some separator in category names, if it helps. Then you could set some office.type categories and query/sort/output them as desired.

Offline

#4 2024-09-02 15:45:47

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Re: Ideas for emulating two file download categories?

etc wrote #337761:

It costs nothing to replace IN with LIKE in category query and allow for some separator in category names, if it helps. Then you could set some office.type categories and query/sort/output them as desired.

Hey, I like this idea! And extend it to the Links and Images too?

And, a wildcard, maybe even article categories to make faux subcats a possibility? Not sure how it would interact with the URL /category route, but I can’t see a major problem as it’ll just list the matching category as normal, as long as we don’t filter out potentially useful delimiters.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2024-09-03 15:58:54

etc
Developer
Registered: 2010-11-11
Posts: 5,188
Website GitHub

Re: Ideas for emulating two file download categories?

I have tried it for files, using - (which is allowed in category names) as separator, and this seems to work:

<!-- retrieve all office logos -->
<txp:file_download_list category="office-logos" />

<!-- retrieve all office assets -->
<txp:file_download_list category="office-%" />

<!-- retrieve all logos and reports -->
<txp:file_download_list category="%-logos, %-reports" />

Looks hackish, but should not hurt anyway.

Offline

#6 2024-09-03 19:00:57

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Re: Ideas for emulating two file download categories?

Niiice! Great tip.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2024-09-03 20:43:28

etc
Developer
Registered: 2010-11-11
Posts: 5,188
Website GitHub

Re: Ideas for emulating two file download categories?

Wait, it’s only on my localhost atm :-) But I can push it to dev (for images/links too) if it solves any problem.

Offline

#8 2024-09-04 05:54:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Re: Ideas for emulating two file download categories?

Yes please. Sounds like a useful enhancement.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2024-09-04 06:01:48

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Re: Ideas for emulating two file download categories?

I agree, that sounds promising. I’m pushed for time to give this a proper try right now, but it looks like it could fit the bill.


TXP Builders – finely-crafted code, design and txp

Offline

#10 2024-09-05 10:20:50

etc
Developer
Registered: 2010-11-11
Posts: 5,188
Website GitHub

Re: Ideas for emulating two file download categories?

There is one little problem: sql underscore wildcard _ is allowed in txp category names. Thus searching for category="my_card" would also return an eventual myocard etc, which is not bwc.

Thoughts?

Offline

#11 2024-09-05 11:05:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Re: Ideas for emulating two file download categories?

Drat. Hate SQL for that. But I guess it’s no less random than regex using a dot. Hmmm.

Training people to use category="my\_card is one option! But backwards compatibility still suffers.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#12 2024-09-05 11:12:04

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Re: Ideas for emulating two file download categories?

Or maybe we don’t pass the thing directly to SQL but preprocess it? Internally replace underscores with \_ and just document it that if people want to use wildcards they need to use * which we internally preprocess to a regular underscore before passing to SQL.

Bit of a hack.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB