1. 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

Discussion in 'XenForo Development Discussions' started by AndyB, Nov 13, 2014.

  1. AndyB

    AndyB Well-Known Member

    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:

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


    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.


    Thank you for taking the time to look at this issue.
    Last edited: Nov 13, 2014
  2. AndyB

    AndyB Well-Known Member

    This Template Modification does work as it's not using the xenOptions in the Find field.

  3. AndyB

    AndyB Well-Known Member

    I just tried adding the Positions into the forum_list template directly, but that doesn't work either.


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

    Valhalla Well-Known Member

  5. AndyB

    AndyB Well-Known Member

    That's not a problem at all, it would just randomly display the add-on in the order which the XenForo code ran.
  6. AndyB

    AndyB Well-Known Member

  7. AndyB

    AndyB Well-Known Member

    This is what I have tried. The Template Modification was changed to:


    And that calls the following PHP file:


    class Andy_Traffic_RegexTM
        public static function 
    'Position 1';
    The result is this in my sidebar:

  8. Chris D

    Chris D XenForo Developer Staff Member

    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.
  9. AndyB

    AndyB Well-Known Member

    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.
  10. rainmotorsports

    rainmotorsports Well-Known Member

    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.
  11. EQnoble

    EQnoble Well-Known Member

    I don't get what doesn't work about it.

    I found the comment here just fine, unless I misunderstand the issue?
  12. Chris D

    Chris D XenForo Developer Staff Member

    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.
  13. cclaerhout

    cclaerhout Well-Known Member

    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.
  14. AndyB

    AndyB Well-Known Member

    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.
  15. cclaerhout

    cclaerhout Well-Known Member

    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.
  16. AndyB

    AndyB Well-Known Member

    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.
  17. AndyB

    AndyB Well-Known Member

    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.
  18. Chris D

    Chris D XenForo Developer Staff Member

    It works fine, Andy.


    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.
  19. AndyB

    AndyB Well-Known Member

    I have an add-on called Traffic.
    In the Options page of the Traffic add-on I have a field called Position


    The Option ID = trafficPosition

    I have added the following to the forum_list template:


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


    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.
  20. Chris D

    Chris D XenForo Developer Staff Member

    Your template does not contain {$xenOptions.trafficPosition}, it contains Position 1.

    It doesn't work how you think it should.

Share This Page