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: 15

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: 82

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: 8,342
Website

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.org | hblack.net | State Machines | NeMe @ github
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: 15

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: 9,829
Website

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: 15

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: 15

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: 8,342
Website

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.org | hblack.net | State Machines | NeMe @ github
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: 9,829
Website

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: 15

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

Board footer

Powered by FluxBB