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

Regular expression and the new template modification system...

Discussion in 'XenForo Development Discussions' started by Liam W, Jun 19, 2013.

  1. Liam W

    Liam W Well-Known Member

    So, I'm trying to update my addon for xenForo 1.2 and make use of the TMS built in...

    Unfortunately, I cannot get it to work. I have chosen PHP callback, but it just doesn't apply :(

    I need to match an exact piece of text. I would use a standard find/replace but I need to use variables in the templates so it doesn't work.

    Also, I can't use the old hook system as it's been deprecated...

    Any ideas?

  2. Chris D

    Chris D XenForo Developer Staff Member

    You could use the old hook system. It's still there. And maybe it will remain for sometime. The disabling of it hasn't really been discussed.

    What are you actually trying to do? PHP callback might not be necessary.

    My Recent Members add-on uses regular expressions. Use that for a pretty basic one that inserts some code after some existing matching code.
  3. Liam W

    Liam W Well-Known Member

    Are you sure it's still there? When I tried to test my addon out, it didn't work. The template hook code hadn't been inserted at all :/

    I'm trying to find the start of a form, add my code before it, and then make sure the start of the form is there again. However, my code is in a template, and it needs template variables to be passed to it...

    Edit: Oh, yeah it is there still :p

    However, this system would make it cleaner...
  4. Chris D

    Chris D XenForo Developer Staff Member

    That's exactly the function my add-on has.

    1) There's a template modification that uses a regular expression to include a template after a block of code (a <xen:if statement rather than a form but you'll get the idea).

    2) There's a listener which extends the member controller and all that does is a quick query and adds the result of that query in to the view parameters which will then be straight away available in your template.

    Download my add-on, install it, change the title and add-on ID, understand what it does and then adjust it to your needs. It seems pretty much exactly what you need.

    Obviously the only downside is, if you're using the new TM system then it wil only be compatible with XenForo 1.2.x.
  5. Liam W

    Liam W Well-Known Member

    Yeah, I'm going to stick with the hooks for now.

    Issue is, my addon just can't work with redactor... The redactor variable isn't defined in javascript, like tinymce was :(
  6. cclaerhout

    cclaerhout Well-Known Member

    See this request.

    You can try to use this function: var editor = XenForo.getEditorInForm($form);
    You need to get the form of the editor you want to use, then you should get the API. I will have to try this the next week for the quotme addon.
    Liam W likes this.
  7. Liam W

    Liam W Well-Known Member

    How would I get the form? Sorry, I know PHP but javascript is like a foreign language (except the simple parts)...

    EDIT: As I am adding the main form in anyway, I just added an ID to the form and all is working well. *sigh of relief*. Thanks!
  8. cclaerhout

    cclaerhout Well-Known Member

    What is your plugin? If there's a trigger button somewhere for each editors (for example a button), you can have access to the active editor since it will be the closest to the trigger element. If there's no trigger button, I don't see any solution. I thought I've read a way to get the current active editor with Redactor but it seems I've mistaken. I can't find anything in the api.

    So if there's a trigger button, this is basic jQuery. You find your element by its css id or css class or other ways (read the jQuery documentation for this). Let's say your trigger button class is "myTriggerButton", you will have to use something like this:
    $form = $('.myTriggerButon').closest('form');
    var editor = XenForo.getEditorInForm($form);
  9. Liam W

    Liam W Well-Known Member

    Yeah, but my button was in a different form to the editor, so yeah :p

    Did manage to get it working though, thanks!
    cclaerhout likes this.

Share This Page