Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2025-04-16 22:41:08
- bashirnoori
- Member
- From: Afghanistan
- Registered: 2012-10-02
- Posts: 83
check if file title available
I am making a page to download uploaded files, following is my code, but I want to check if the file title is available fetch that, if not available then fetch file name.
<div class="download_files">
<txp:file_download_list wraptag="" break="">
<div class="item" data-extension='<txp:file_ext />'>
<a href="<txp:file_download_link />">
<i class="icon icon-file-pdf"></i>
<txp:file_download_name />
</a>
[<txp:file_download_size format="mb" decimals="2" />]
</div>
</txp:file_download_list>
</div>
I tried this, but didn’t work ;-)
<txp:if_file_title>
<txp:file_title />
<txp:else />
<txp:file_download_name />
</txp:if_file_title>
Offline
Re: check if file title available
You should be able to use <txp:file_download_name title />
and it’ll display that if it exists, otherwise fall back on the name.
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 2025-04-17 00:40:56
- bashirnoori
- Member
- From: Afghanistan
- Registered: 2012-10-02
- Posts: 83
Re: check if file title available
I tried that and showing just the titles, works same like <txp:file_download_name title="1" />
Offline
Re: check if file title available
Have you tried the following?
<div class="download_files">
<txp:file_download_list wraptag="" break="">
<div class="item" data-extension='<txp:file_ext />'>
<a href="<txp:file_download_link />">
<i class="icon icon-file-pdf"></i>
<txp:file_download_name />
</a>
<txp:variable name="file_title"><txp:file_download_name title="1" /></txp:variable>
<txp:if_variable name="file_title">
<txp:variable name="file_title" />
<txp:else />
<txp:file_download_name />
</txp:if_variable>
[<txp:file_download_size format="mb" decimals="2" />]
</div>
</txp:file_download_list>
</div>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: check if file title available
Bloke wrote #339543:
You should be able to use
<txp:file_download_name title />
and it’ll display that if it exists, otherwise fall back on the name.
A test on the dev demo doesn’t confirm the fallback.
bashirnoori wrote #339542:
I am making a page to download uploaded files, following is my code, but I want to check if the file title is available fetch that, if not available then fetch file name.
Another alternative to the txp:variable method that Yiannis posted is this:
<txp:evaluate test="file_download_name">
<txp:file_download_name title />
<txp:else />
<txp:file_download_name />
</txp:evaluate>
[If you happen to read this right away, you can see it in action on the dev demo.
TXP Builders – finely-crafted code, design and txp
Offline
Re: check if file title available
jakob wrote #339546:
A test on the dev demo doesn’t confirm the fallback.
Dammit. My gut feeling says it should, but I dunno. If you’ve asked for titles and it did fall back in their absence, we wouldn’t be able to test for the non-existence of them, which would render the evaluate tests above useless.
On second thoughts then, leaving it as-is works better.
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
Re: check if file title available
You can also shorten it to
<txp:file_download_name title default='<txp:file_download_name />' />
Offline
Re: check if file title available
etc wrote #339549:
You can also shorten it to
<txp:file_download_name title default='<txp:file_download_name />' />...
Eloquent! Does default
work across the board, or only on some tags?
TXP Builders – finely-crafted code, design and txp
Offline
Re: check if file title available
etc wrote #339549:
You can also shorten it
Of course! That’s clever. Should have thought of that myself. I tend to forget the default
attribute is global.
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
Offline
#11 Today 20:07:56
- bashirnoori
- Member
- From: Afghanistan
- Registered: 2012-10-02
- Posts: 83
Re: check if file title available
etc wrote #339549:
You can also shorten it to
<txp:file_download_name title default='<txp:file_download_name />' />...
This works perfect, thank you :-)
Offline
Pages: 1