XF 2.2 Calling a snippets files with custom conditionals settings & variables?

I'm fairly new to modifying and theme customisation for Xenforo. I'm looking to create a snippets file house house all my theme customisations. If you're familiar with Shopify, Shopify has a snippets section that you can house all your theme mods, etc.

I'm looking to achieve something similar with Xenforo.

For example, I've made some page_container tweaks to the HEAD such as titles, descriptions & schema. If I keep continuing to apply theme mods to page_container it will start to become very cluttered. What I want to be able todo, it write those modifactions in a seperate file and call it in the page_container file. Any tips on how I can achieve this?

Examples:
I'm writing custom page titles and meta descriptions. If I continue down this page the page_container with become very cluttered indeed.

Code:
<!-- page title & description modifications -->
    
<!-- page title -->
<xf:if is="$containerKey == 'node-10'">
<title>Node custom page title goes here</title>
<xf:else />
<title><xf:title formatter="%s | %s" fallback="{$xf.options.boardTitle}" page="{$pageNumber}" /></title>
</xf:if>
 
<!-- meta description -->
<xf:if is="$containerKey == 'node-10'">
<meta name="description" content="Node custom meta description goes here"/>
<xf:else />
<meta name="description" content="{$description}"/>
</xf:if>

Structured data, which I plan to implement based on page types, breadcrumb depth, etc.
Code:
<!-- structured data -->
<script type="application/ld+json">
{
  "@context": "https://schema.org/", 
  "@type": "BreadcrumbList", 
  "itemListElement": [{
    "@type": "ListItem", 
    "position": 1, 
    "name": "Home",
    "item": "{{ link('canonical:index')|escape('js') }}"   
  },{
    "@type": "ListItem", 
    "position": 2, 
    "name": "{$h1}",
    "item": "{$xf.fullUri}"  
  }]
}
</script>

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "WebPage",
    "name": "{$h1}",
    "description": "{$description}",
    "publisher": {
        "@type": "WebPage",
        "name": "{$xf.options.boardTitle}"
    }
}
</script>


I'm not really looking to achieve this by utilising addons, looking todo this manually.

Thanks for reading.
 
I have found a possible workaround by using a HTML widget, but the problem with that, is that the widget is wrapped in a class called "block". I'm unable to remove that widget wrapper class.


EDIT: I figured this one out. I created a new template and called it from within the head in the page_container. worked a treat.
Code:
 <xf:include template="structured_data" />
 
Last edited:
Top Bottom