Managing Structured Data via PHP Classes Instead of Templates in XenForo

CihanOnline

Member
Hi everyone,

I've noticed a significant shift in how structured data is handled in recent XenForo updates. It appears that structured data is no longer directly managed within the templates but rather is generated through PHP classes. This seems to align with modern practices, emphasizing separation of concerns and streamlining the presentation layer from the data logic.

However, this transition raises a few questions and considerations for forum administrators and developers:

1. What are the key benefits of managing structured data through PHP classes over inline template management?
2. How does this change affect the customizability of structured data for those who are used to handling it via templates?
3. For developers, what are the best practices to extend or customize structured data generation in XenForo while ensuring upgradability and maintainability?
4. Are there any performance implications with this approach, and how does it impact page load times and server processing?
5. Lastly, for those who want to revert to template-based management, what options or plugins are available?

I believe this discussion could help us better understand the direction XenForo is heading and how we, as a community, can adapt to these changes effectively. Looking forward to your insights and experiences.
 
Following the recent updates to XenForo, especially with the move towards managing structured data through PHP classes, I’ve come across a challenge that I believe could be common among us. In previous versions, adding and adjusting structured data was straightforward using the xfrm_resource_view template. Now, with structured data being handled by PHP classes, I’m wondering about the new best practices for including custom fields from XFRM resources in the structured data.

The specific prompt from Google Search Console has made it clear that the structured data needs to be comprehensive and include these custom fields to meet their guidelines. Could anyone share insights or point towards resources on how to extend the structured data generation to include custom fields from the XFRM ResourceItem entity?

Any examples, code snippets, or extensions that could assist with this integration would be greatly appreciated. The goal is to ensure that our resources remain rich in detail and fully compliant with SEO best practices.

 
Last edited:
I am not a XenForo developer, so this is not an official answer.

1. What are the key benefits of managing structured data through PHP classes over inline template management?
It is much more structured, less fragile and easier to extend / modify for 3rd party code than hardcoded text in templates.

2. How does this change affect the customizability of structured data for those who are used to handling it via templates?
IMHO it doesn't change customizability at all, in fact it does make it easier as it is now just an array (instead of a hardcoded string) that can be modified easily.

3. For developers, what are the best practices to extend or customize structured data generation in XenForo while ensuring upgradability and maintainability?
Create class extensions to modify the generated array.

4. Are there any performance implications with this approach, and how does it impact page load times and server processing?
Every bit of code does have a (positive or negative) performance impact - even if you just modify a template this does have an impact.
Probably hardly even measurable let alone noticable, but it is there for sure.

5. Lastly, for those who want to revert to template-based management, what options or plugins are available?
None that I am aware of and quite frankly - it wouldn't make sense anyway as it would be a step backwards.
Structured data should be handled in a structured way, not as unstructured hardcoded text.
 
Last edited:
That pretty much covers it. Templates make certain things easier (like outputting HTML for display) at the expense of making other things difficult (like building up an array of structured data). The old approach was more difficult to author and extend. I would highly recommend using class extensions for making comprehensive customizations, but it is still possible to use templates with the |replace filter:

HTML:
<xf:page option="ldJsonHtml">
    <script type="application/ld+json">
        {{ $resource.getLdStructuredData()|replace({
            'key': 'value',
            'key2': {
                'subkey': 'subvalue'
            }
        })|json(true)|raw }}
    </script>
</xf:page>
 
Top Bottom