• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XenOptions not working in Template Modifications Find

AndyB

Well-known member
#1
My goal is to have an easy way to change the position of any of my add-ons in the sidebar.

I have created an add-on called Sidebar Hooks, the idea is that this add-on will be required to position any of my sidebar add-ons.

The Sidebar Hooks Template Modification modifies the "forum_list" template like this:

pic001.jpg
Then in the Options of portion of all my add-ons which will show in the sidebar I will include the following:

pic002.jpg

The problem is the add-on Template Modification appears to not work in the "Find" field if it's trying to find code which has been added by another add-on using the Template Modification.

Example of Template Modification (template = forum_list) with the Find not working using a $xenOptions.

pic003.jpg

Thank you for taking the time to look at this issue.
 
Last edited:

AndyB

Well-known member
#3
I just tried adding the Positions into the forum_list template directly, but that doesn't work either.

pic005.jpg

It appears that in Template Modifications you cannot use $xenOptions in the Find field.
 

AndyB

Well-known member
#7
This is what I have tried. The Template Modification was changed to:

pic001.jpg

And that calls the following PHP file:

PHP:
<?php

class Andy_Traffic_RegexTM
{
    public static function getCallback($matches)
    {
		return 'Position 1';
	}
}
The result is this in my sidebar:

pic002.jpg
 

Chris D

XenForo developer
Staff member
#8
The problem is the add-on Template Modification appears to not work in the "Find" field if it's trying to find code which has been added by another add-on using the Template Modification.
You cannot find content added by other template modifications.

The Test Modification button should show that, as would the template contents that appear; you should not see any other TMs that have applied to that template.
 

AndyB

Well-known member
#9
You cannot find content added by other template modifications.
Hi Chris,

Thank you for taking the time to look at this thread.

In my testing (see post #3) I tried putting the <xen:comment>Position 1</xen:comment> comments directly into the forum_list template and even then the xenOptions will not work in the Find field. So it appears $xenOptions is not currently supported in the Find field of Template Modifications.
 

rainmotorsports

Well-known member
#10
I don't think comments are supposed to work for that anyways. I could be wrong. But you can put hooks into the template and do a find replace on them. That for a fact works.
 

Chris D

XenForo developer
Staff member
#12
even then the xenOptions will not work in the Find field.
In post # 3 the forum_list template doesn't even contain xenOptions.

Just simplify the test case:

1) Create a new template in the Master Style called: tm_test
2) Add the following content to it: {$xenOptions.boardUrl}
3) Create a new template modification, applied to tm_test. Find: {$xenOptions.boardUrl} replace {$xenOptions.boardTitle}
4) Edit the forum_list template, at the top place <xen:include template="tm_test" />. Go to the forum list.
5) Result: You will see the board title instead of the board URL. Therefore, it works fine.

Whatever problems you are having, it isn't that.

Despite what I said earlier, it should in theory be possible to find/replace on the replacements of previous TMs but make sure you use a logical execution order.
 

cclaerhout

Well-known member
#13
I don't understand what you're trying to do and the relations between the different elements you give:
What's the relation between the template modification with many comments, the one with the $xenOptions variable, and the option showed?

If I look what you try to do and revert the idea, here's what I get:
You create some text hooks in a template using a template modification. Based on those hooks, you create a new template modification that targets one of the comment to insert a custom html code. This will work without any problem providing the templates modifications order is correct (first mod must perform before the second one). So now, you're thinking of creating a new layer of code to allow to target these comments by a XenForo option. Here's a possible loophole: the template modifications are not applied in live (when the page is loaded), so if you think to insert a XenForo option in the find box and that this option will look for the actual value of this option to perform the replacement, you're mistaken. It will only look for the text your enter in the find box, nothing more. Don't forget also that the xenforo comments are strip in the final output. I think you need to rethink your process.
 

AndyB

Well-known member
#14
so if you think to insert a XenForo option in the find box and that this option will look for the actual value of this option to perform the replacement, you're mistaken. It will only look for the text your enter in the find box, nothing more.
This is exactly what I have found to be the case. Although there appears to be one exception to this rule, I have found that {$xenOptions.boardTitle} will work, but that won't be useful for my needs.
 

cclaerhout

Well-known member
#15
This is exactly what I have found to be the case. Although there appears to be one exception to this rule, I have found that {$xenOptions.boardTitle} will work, but that won't be useful for my needs.
Just to be sure we're talking about the same thing.
Let's suppose the variable {$xenOptions.boardTitle} value is "My Board". When you create a template modification and search for "{$xenOptions.boardTitle}" in the search field, it will really look for the text "{$xenOptions.boardTitle}", not its value "My Board". You an create a new xenForo option, insert it in a template, create then a template mod, find this variable name in template, then replace it with something else, it will work. The template modification system is really like a standard search/replace system on the template text content. Using a callback will not change this. If you need to work with the output code, use the template hooks or inject variable in a template using the template create listener.
 

AndyB

Well-known member
#16
Create a new template modification, applied to tm_test. Find: {$xenOptions.boardUrl} replace {$xenOptions.boardTitle}
Hi Chris,

It appears {$xenOptions.boardTitle} is the only exception as that works. Please try a test using another $xenOptions and see if you come to the same results as I have in that $xenOptions will not work in Template Modifications "Find" field excluding the one exception as previously stated.
 

AndyB

Well-known member
#17
Let's suppose the variable {$xenOptions.boardTitle} value is "My Board".
Hi cclaerhout,

First thank you for your time, I really appreciate this.

What I have found in my testing is that {$xenOptions.boardTitle} is the only exception to the rule. If I try for example {$xenOptions.trafficPosition} or any other type of $xenOptions.foobar} in the Template Modifications "Find" field, it will not work.
 

Chris D

XenForo developer
Staff member
#18
It works fine, Andy.

upload_2014-11-14_15-45-46.png

You need to start again and explain steps in detail which lead you to it not working.

It's not completely clear how to reproduce the issue you're reporting.
 

AndyB

Well-known member
#19
I have an add-on called Traffic.
In the Options page of the Traffic add-on I have a field called Position

pic001.jpg

The Option ID = trafficPosition

I have added the following to the forum_list template:

pic002.jpg

I have create a Template Modification for Traffic and it looks like this:

pic003.jpg

So what should happen is that the "Find:" should have a value of "Position 1", and should be be replaced by the contents in the "Replace:" box.
 

Chris D

XenForo developer
Staff member
#20
Your template does not contain {$xenOptions.trafficPosition}, it contains Position 1.

It doesn't work how you think it should.