• REGISTRATION REQUIREMENTS:

    Your username here MUST MATCH your XenForo username (connected to your XF license).

    Once you have registered here, then you need to start a conversation at xenforo.com w/Bob and provide the following:
    1. Your XenForo License Validation Token
    2. The Domain Name associated with the License
    NOTE: Your account will be validated once ALL requirements are verified/met. Thank you for your patience.

Implemented Fetch LD Structured Data via getLdStructuredData() function in the Blog, Entry, Page & Series Entity

Bob

Developer
Staff member
As per title, fetch/set LD Structured Data via getLdStructuredData() function in the Blog Entity, Blog Entry Entity, Page Entity and Series Entity.

UBS now uses the same standard as Thread Types and XFMG use to fetch/set LD Structured Data (and soon XFRM).

Here is an example (this is what the template code in the xa_ubs_blog_entry_view template looks like now. It uses extensions and a function call.

HTML:
<xf:page option="ldJsonHtml">
    <xf:extension name="structured_data_extra_params" value="{{ [] }}" />
    <xf:extension name="structured_data">
        <xf:set var="$ldJson"
            value="{{ $blogEntry.getLdStructuredData($page, extension_value('structured_data_extra_params')) }}"
        />
        <xf:if is="$ldJson">
            <script type="application/ld+json">
                {$ldJson|json(true)|raw}
            </script>
        </xf:if>
    </xf:extension>
</xf:page>


Quick example on how to use template extensions (use the XenForo Developers Forum if you want to learn more about template extensions in general). This example is used in the thread_view_type_question template to pass in some additional structured data params to the thread_view template which uses the same type of template code shown above...


HTML:
<xf:extends template="thread_view" />
<xf:extension name="structured_data_extra_params" value="{{ {
    'highlightedPosts': $highlightedPosts,
    'suggestedSolutions': $suggestedSolutions
} }}" />


And this is in the thread_view template. The above extension is passing data into the structured_data_extra_params extension, which will then be passed into the getLdStructuredData function in the Thread Entity.

HTML:
<xf:page option="ldJsonHtml">
    <xf:extension name="structured_data_extra_params" value="{{ [] }}" />
    <xf:extension name="structured_data">
        <xf:set var="$ldJson"
            value="{{ $thread.getLdStructuredData($firstPost, $page, extension_value('structured_data_extra_params')) }}"
        />
        <xf:if is="$ldJson">
            <script type="application/ld+json">
                {$ldJson|json(true)|raw}
            </script>
        </xf:if>
    </xf:extension>
</xf:page>


Note: For those of you that don't know how to do things the modern way (template extensions and extending classes) and you want to customize the ldJsonHtml on your own, just copy the old ldJsonHtml template code before upgrading and replace the new template code with the old template code. Keep in mind, this is NOT supported, so doing that is an own your own type thing, just making sure that you are aware that you can do that upload_2023-8-6_7-22-8.gif
 
Upvote 0
This suggestion has been implemented. Votes are no longer accepted.
Back
Top