XF 2.2 Altering JSON field value in XF Template

Cupara

Well-known member
I'm grabbing JSON data from various sources but here is the link to one source: https://us.forums.blizzard.com/en/wow/groups/blizzard-tracker/posts.json

What I'm trying to do is process everything as I do but in my template using either bbcode{} tag or another method to convert <a href> tag to bb_code so it will display the URL properly.
  1. Is there a way to convert the HTML code in the excerpt field value to BBCode [ URL ] tag?
  2. Is there a way for me to grab say 7 different JSON bodies and combine them into one then use a foreach in my template to display them grouped by date?
  3. How can I limit the results displayed on my page based on a setting?
  4. How do I paginate my results say display 10 results then the second page for the last 10 results?
The JSON links I use only have 20 entries and that is all that is sent in the JSON.
 
Solution
For #1: I believe you should do that in the PHP as I don't know any regex functions in XF templates. I think you are already using a PHP script to grab the data, so you just need to alter data to be passed to the template. Simply regex.

Or, you can create a custom BB code to wrap each record, for example [EXCERPT]text here[/EXCERPT], and render this BB code by doing the same regex transformation below.

PHP:
$excerpt = '<a href="https://bnetcmsus-a.akamaihd.net/cms/blog_header/jw/JWRN080CYTAL1584035056216.jpg">[World of Warcraft Student Art Contest 2020]</a> Students, the time has come to show off your talents: The World of Warcraft Student Art Contest has returned!  <a href="https://worldofwarcraft.com/en-us/news/23545415">View Full Article</a>'...
For #1: I believe you should do that in the PHP as I don't know any regex functions in XF templates. I think you are already using a PHP script to grab the data, so you just need to alter data to be passed to the template. Simply regex.

Or, you can create a custom BB code to wrap each record, for example [EXCERPT]text here[/EXCERPT], and render this BB code by doing the same regex transformation below.

PHP:
$excerpt = '<a href="https://bnetcmsus-a.akamaihd.net/cms/blog_header/jw/JWRN080CYTAL1584035056216.jpg">[World of Warcraft Student Art Contest 2020]</a> Students, the time has come to show off your talents: The World of Warcraft Student Art Contest has returned!  <a href="https://worldofwarcraft.com/en-us/news/23545415">View Full Article</a>';

$urlized = preg_replace('/<a href="(.*)">(.*)<\/a>/U', '[URL=$1]$2[/URL]', $excerpt );

print $urlized;

This will return the following:
[URL=https://bnetcmsus-a.akamaihd.net/cms/blog_header/jw/JWRN080CYTAL1584035056216.jpg][World of Warcraft Student Art Contest 2020][/URL] Students, the time has come to show off your talents: The World of Warcraft Student Art Contest has returned! [URL=https://worldofwarcraft.com/en-us/news/23545415]View Full Article[/URL]
Which will be rendered as:
[World of Warcraft Student Art Contest 2020] Students, the time has come to show off your talents: The World of Warcraft Student Art Contest has returned! View Full Article
 
Solution
Top Bottom