Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-10-22 00:53:46

Bruce Bowden
Member
From: Melbourne, Australia
Registered: 2020-10-22
Posts: 28

Adding file links to articles

Brief backstory: I used Silverstripe CMS for many years but as time went on, I was doing less development and Silverstripe was moving up in sophistication. Time to find a new, simpler platform for the odd site I am still building. First try: Bolt. A week later, and I was still trying to get a stable site I could start developing. Second try: Textpattern. 1 hour later and I had a functional site on my Raspberry Pi. I have found my new platform!

Ok, now to my first question. I am building an “intranet” for our group of units with meeting minutes, the rubbish bin roster, etc. This means lots of links to files. My first pass through the docs suggests that I need to insert the file links within the article text, linking to the file ID each time. So: upload a bunch of files, note the file IDs, then build links in the article using those IDs.

Any other ideas? It would be lovely to be able to associate a file or files with an article, then I could build a form to show the list of files associated with the article. Maybe subvert the Category function?

Offline

#2 2020-10-22 03:28:06

code365
Member
From: California
Registered: 2009-08-16
Posts: 117

Re: Adding file links to articles

I believed this will give you a list of article links. I hope this is some help.
——

<a class="url-text" href="<txp:permlink />">
<txp:title />
</a>

Last edited by code365 (2020-10-22 03:28:54)

Offline

#3 2020-10-22 05:10:22

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

Re: Adding file links to articles

Bruce Bowden wrote #326491:

Brief backstory: I used Silverstripe CMS for many years but as time went on, I was doing less development and Silverstripe was moving up in sophistication. Time to find a new, simpler platform for the odd site I am still building. First try: Bolt. A week later, and I was still trying to get a stable site I could start developing. Second try: Textpattern. 1 hour later and I had a functional site on my Raspberry Pi. I have found my new platform!

Ok, now to my first question. I am building an “intranet” for our group of units with meeting minutes, the rubbish bin roster, etc. This means lots of links to files. My first pass through the docs suggests that I need to insert the file links within the article text, linking to the file ID each time. So: upload a bunch of files, note the file IDs, then build links in the article using those IDs.

Any other ideas? It would be lovely to be able to associate a file or files with an article, then I could build a form to show the list of files associated with the article. Maybe subvert the Category function?

Hi and welcome to txp.
You could use a custom field. First go to Admin>Preferences>Custom Fields, and name one of them FilesCF.

In your default form (Presentation>Forms) – or the form you are using for your articles – add:

<txp:if_custom_field name="FilesCF">
<txp:file_download_list id='<txp:custom_field name="FilesCF" />'>
<txp:file_download_link><txp:file_download_name /></txp:file_download_link> (<txp:file_download_size format="mb" decimals="2" />)
</txp:file_download_list>
</txp:if_custom_field>

You will now be able to add a comma separated list of the file ids in the custom_field of the article and not worry about copy pasting the code each time you wish to link to a file.

More info about the file tags can be found here.

EDIT: (bloke) closing tag

Edit 2: closing tag

Last edited by colak (2020-10-22 09:52:13)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#4 2020-10-22 07:32:02

Bruce Bowden
Member
From: Melbourne, Australia
Registered: 2020-10-22
Posts: 28

Re: Adding file links to articles

Hi Yiannis,
I like your solution. I think that will solve much of my problem.

Stay safe
Bruce

Offline

#5 2020-10-22 07:36:22

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

Re: Adding file links to articles

Hi Bruce, welcome to Textpattern, and glad you found us.

Similar to what colak suggests and you intimate, you can ‘link’ articles and files via some naming convention. A custom field is one method and gives you greatest flexibility. You could also use Category (perhaps if you’re not using them for anything else) but that requires two identical trees and means you’d get the same files attached to each article that has the same category.

If you need a unique set of files per article, consider using the url title as a link. e.g. make a File category tree under some parent (such a intranet-files for housekeeping purposes) that contains the url-title of each article that has files associated with it.

When you upload the files for an article, drop them in the category that matches the url-title of the article; you can use the article’s human-readable title as Category title if you like, to make it easier to match visually with the actual article.

In your form that displays the list of files, you can then do something like this:

<txp:file_download_list category='<txp:article_url_title />'>
   <txp:file_download_link>
      <txp:file_download_name title /></txp:file_download_link>
      (<txp:file_download_size format="mb" decimals="2" />)
   </txp:file_download_link>
</txp:file_download_list>

Hope that gives you some ideas.

EDIT: and if you find naming the categories a chore, write a few-line plugin to do it for you automatically when you Save/Publish an article – it could auto-generate the category for you if it doesn’t exist, based on the article URL title.

Last edited by Bloke (2020-10-22 07:37:55)


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

#6 2020-10-22 09:07:27

Bruce Bowden
Member
From: Melbourne, Australia
Registered: 2020-10-22
Posts: 28

Re: Adding file links to articles

Hi Yiannis,
Your code had a couple of mistakes. Which is wonderful! The error messages popped up, I was able to see what needed fixing, and now it all works.

A much better outcome than just pasting someone’s code.

For what it’s worth, here is the adjusted code:

<txp:if_custom_field name="FileIDs">
<txp:file_download_list id='<txp:custom_field name="FileIDs"/>'>
<txp:file_download_link><txp:file_download_name /></txp:file_download_link> (<txp:file_download_size format="mb" decimals="2" />)
</txp:file_download_list>
</txp:if_custom_field>

And now I know how to use textile to show my code block! Multiple wins.

Stay safe
Bruce

Offline

#7 2020-10-22 09:13:47

Bruce Bowden
Member
From: Melbourne, Australia
Registered: 2020-10-22
Posts: 28

Re: Adding file links to articles

Having just got Yiannis’ solution working, Bloke offers what is a near-perfect answer to my needs.

Thank you, guys. Wonderful responses from you both.

Stay safe
Bruce

Offline

#8 2020-10-22 09:59:47

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

Re: Adding file links to articles

Hi Bruce,
Apologies for the typos in my code. My responses in the forum are normally very quick and instinctive, and unfortunately do often contain code errors.

Glad you sorted it out.

Regarding Bloke’s suggestion, which I like in principle, but I guess it may also depend on how many articles you expect to be produced by the users. You would not want to have 2000 categories.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#9 2020-10-22 10:23:19

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

Re: Adding file links to articles

Yeah, it does depend on the expected number of articles.

As I say, the CF solution is more flexible as long as you don’t mind putting the IDs in a list. A plugin could, again, help out here in a similar manner to the way that com_article_image does for images, allowing you to pick files to attach to an article and auto-populate the IDs for you in a custom field.


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

#10 2020-10-22 20:38:36

Bruce Bowden
Member
From: Melbourne, Australia
Registered: 2020-10-22
Posts: 28

Re: Adding file links to articles

Hi guys,
I will probably use both solutions in different areas. It’s not a big site so the categories shouldn’t explode. The upper limit is more like 100 than 2000.
And a fast response with a couple of typos is much more appreciated than a considered one that appears days later. And I learnt from it!

I might look at how com_article_image works as well.

Stay safe
Bruce

Offline

#11 2020-10-24 09:29:13

Bruce Bowden
Member
From: Melbourne, Australia
Registered: 2020-10-22
Posts: 28

Re: Adding file links to articles

Hi guys,
I have been looking at smd_tags and it ‘almost’ does what I want straight out of the box. An example of what I want to achieve: We meet 4 times a year and each meeting generates a number of files.
I created identical lists of tags for both articles and files:
2020, 2019, 2018, March, June, September, December
The article for the June 2020 meeting is tagged ‘June, 2020’ and it’s related files tagged the same.

Unfortunately, smd_related_tags, as you know, gives me all the files with either ‘2020’ or ‘June’, not just files with both ‘June’ and ‘2020’.

I can see in the plug-in admin panel that somewhere I can use AND but can’t work out how to use the power of smd_tags to do what I need.

I had a quick look at the help file for com_article_image but at this stage, tags look to be the fastest way to set up the site.

Thanks in advance for any suggestions.

Stay safe
Bruce

ps, I’m glad in Australia. Our state, Victoria, had 750 cases a day in July, same as the UK at the time. Our current 14 day average is only 5 cases a day. The lockdown has been harsh but almost everyone stuck with it and now we can reap the rewards.

Offline

#12 2020-10-24 09:41:43

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

Re: Adding file links to articles

If you want to use smd_tags, look at the tag preferences. The URL management allows you to filter in the URL by using combinators. By default, for example:

example.org/tags/article/june+2020 = articles containing BOTH tags
example.org/tags/article/june|2020 = articles containing EITHER tag

In terms of building the URLs by allowing people to click to add/subtract tags, that’s more tricky. I’ve never done it, but it should be possible with a form that auto-submits when you change selections. Display all the tags in a list with checkboxes alongside each. When submitted, check the form submission and then just concatenate all the selected options with ‘+’ between them and tack them onto the base URL (which you can get from <txp:page_url />).

If there’s nothing submitted, you can set the URL to the base page. And if you wanted to be really fancy you could add an option to the form to allow people to choose between ‘all’ and ‘any’ term, adjusting your separator accordingly.

Hope that helps.


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