XF 2.2 How to display image conditional on certain pages/nodes?

oldford

Active member
I have a custom style with a header containing banner ads. I would like to show a different banner on different pages, for example banner #1 on forum pages, banner #2 on XFMG pages, etc.

Is there a conditional I can put into my header HTML to control this?

Thanks!
 
Hello, for forum home you can use this code
HTML:
<xf:if is="$template == 'forum_list'">
    Content
</xf:if>
Change the template name (forum_list in this example) for the others pages.
 
Thank you. That works. My only concern now is there are a lot of templates to identify and I'm not sure how to do that. I know where the templates are in Admin CP, but I don't know which is the main page template for each area.

Also, I'm not sure how to define more than one template at the same time in the conditional.

I'm wondering if there's a better way to do what I'm doing. I will check if @Siropu's Ads Manager addon allows control by template.
 
Excellent. Thanks!

Can I use wildcards in the template selection? I'm targeting templates starting with XFMG_ and XA_

This code works great for those individual templates...
HTML:
<xf:if is="in_array($template, ['xfmg_media_index', 'xa_ams_index'])">

But I'm hoping to use wildcards to target all XFMG_ and XA_ templates.

I tried the code below, but it didn't work (mostly because I'm just cobbling together what I find here on XF without understanding the code)
HTML:
<xf:if is="in_array($template*=['xfmg_', 'xa_'])">
 
Conditional statements don't support wildcards.

I don't know how you plan to implement it but you could create your own var which can be reused:
HTML:
<xf:set var="$array" value="{{ ['value_1', 'value_2', 'value_3'] }}" />

You would then reference that using:
HTML:
<xf:if is="in_array($template, $array)">
 
Top Bottom