• 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 Article, Page and Series Entities

Bob

Developer
Staff member
This was a favor to Xon. This was already implemented in AMS 2.3.0 Beta 1, just pushed out a bit sooner so that Xon can use it now for a client customization.

As per title, fetch/set LD Structured Data via getLdStructuredData() function in the Article Entity, Article Page Entity and Series Entity.

AMS now uses the same standard as Thread Types and XFMG use to fetch/set LD Structured Data.

Here is an example (this is what the template code in the xa_ams_article_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="{{ $article.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
 
Upvote 0
This suggestion has been implemented. Votes are no longer accepted.
Back
Top