Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Check if a file exists within a file category
Hi there,
I need some code to check if at least one file exists within a file category, but am unsure how to write the tags to do that.
Basically it needs to check if the file category ‘current-beta-release’ exists, and then do an action if it does. I’m using 4.7dev so the <txp:evaluate>
tag is available I just don’t know how to implement it in this situation (or if that tag doesn’t do that, then what combination of tags do).
Offline
Re: Check if a file exists within a file category
Hi Phil,
would this be of help?
<txp:if_category type="files" name="current-beta-release">
<txp:file_download_list limit="5" break="li" wraptag="ol" sort="downloads desc" />
<txp:else />
<p>Nothing to download</p>
</txp:if_category>
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 a file exists within a file category
Rethinking about it:)
<txp:variable name="hasbeta"><txp:file_download_list category="current-beta-release" limit="1" break="" wraptag="" sort="downloads desc" /></txp:variable>
<txp:if_variable name="hasbeta" value="">
<txp:else />
<txp:variable name="hasbeta" />
</txp:if_variable>
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 a file exists within a file category
That’s a nice little brain teaser. :-) I got this to work with 4.6.2:
<txp:php>
if (safe_row('name','txp_category','`name` = "current-beta-release" AND `type` = "file"') == true) {
echo 'exists';
}
else {
echo 'does not exist';
}
</txp:php>
Offline
Re: Check if a file exists within a file category
colak wrote #306422:
Rethinking about it
You can also flip the logic in 4.7.0 by using valueless attributes:
<txp:variable name="hasbeta"><txp:file_download_list category="current-beta-release" limit="1" break="" wraptag="" sort="downloads desc" /></txp:variable>
<txp:if_variable name="hasbeta" value>
<txp:variable name="hasbeta" />
<txp:else />
<p>No beta downloads available.</p>
</txp:if_variable>
But jakob nailed it with the <txp:evaluate>
tag, which is neater.
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 a file exists within a file category
Thanks for the help everyone – I used the <txp:evaluate>
version in the end. Final code here.
Offline