XF 2.1 Any way of checking if variable in a template is a valid URL to a local install thread?

Kevin

Well-known member
Here's what I'm working on... I'm working on a widget that pulls a list of threads, some of the threads might have a custom thread field URL value associated with them, that URL may or may not be to a thread in the local XF install.

In my widget output template I'll be working with the custom thread URL value; if it is link to a local install thread then I'd like to display it using the XF preview method, otherwise if it isn't for a local thread then I'll display it as a straight link with no preview.

If not in the template, any way to check the values if I loop through the finder results before returning the results to the template (with the idea being to then add/modify a variable associated to $thread that I could check in the template to choose which method to show the URL). 🤔

Thanks :)
 
You'd need to parse the URLs for IDs and then use a finder to see if they exist in the database. You can see an example of how you might do this in \XF\Repository\Thread::getThreadFromUrl(). This method queries one URL at a time though, so I'd recommend creating your own method rather than using it in a loop.

If you can already assume the thread exists and simply need a way to differentiate the URLs, maybe just do a strpos() check for the board URL or something instead.
 
Back
Top Bottom