Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: [SOLVED] trim and then replace
In the spirit of not repeating yourself, you might have more luck like this:
<txp:variable name="id_num"><txp:yield name="media" /></txp:variable>
<txp:variable name="remote_file">https://cdn.mcstatic.com/contents/videos_screenshots/<txp:variable name="id_num" trim="/(.*)\d{3}/" replace="${1}000" />/<txp:yield name="media" />/830x467/2.jpg</txp:variable>
<txp:php>
$handle = fopen(parse('<txp:variable name="remote_file" />'), 'r');
if ($handle) {
echo '<img src="<txp:variable name="remote_file" />" width="830" height="467" alt="Testing" />';
}
</txp:php>
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Online
Re: [SOLVED] trim and then replace
Thanks Stef, that works.
A last question. Is there a way to expand this in order to check for 3, 4, 5, 6, or 7.jpg if 2.jpg does not exist, and ignore the call if none of them exist?
> Edit: Just in case you missed it: forum.textpattern.com/viewtopic.php?pid=324836#p324836
> Edit 2
Unfortunately the suggestion breaks when there is no image in that url
Last edited by colak (2020-07-27 09:03:43)
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: [SOLVED] trim and then replace
So I am now using the original code I posted but with the variables as Stef suggested.
<txp:variable name="id_num"><txp:yield name="media" /></txp:variable>
<txp:variable name="remote_file">https://cdn.mcstatic.com/contents/videos_screenshots/<txp:variable name="id_num" trim="/(.*)\d{3}/" replace="${1}000" />/<txp:yield name="media" />/830x467/2.jpg</txp:variable>
<txp:php>
$remoteFile = '<txp:variable name="remote_file" />';
$handle = @fopen($remoteFile, 'r');
if(!$handle){
echo 'Image not found';
}else{
echo '<img src="<txp:variable name="remote_file" />" />';
}
</txp:php>
<txp:variable name="remote_file" /><txp:hide>temp: checking if the right url is parsed</txp:hide>
The problem is that I am still getting false negatives, ‘‘Image not found” even though the remote_file variable appears ok. Any ideas?
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: [SOLVED] trim and then replace
You need to use parse() here, as I did in my original example:
$remoteFile = parse('<txp:variable name="remote_file" />');
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Online
Re: [SOLVED] trim and then replace
Bloke wrote #324894:
You need to use
parse()here, as I did in my original example:
$remoteFile = parse('<txp:variable name="remote_file" />');...
Thanks, that indeed, did do it.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline