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

Regex to select the end of template

Discussion in 'XenForo Development Discussions' started by CyberAP, Jun 26, 2013.

  1. CyberAP

    CyberAP Well-Known Member

    I need to paste my code right where the template ends. I am at odds with regex so I am asking you to help me with this. Hope this will also help other people who want to include their code with TM.
     
  2. EQnoble

    EQnoble Well-Known Member

    If you can be more specific I will help you.
     
  3. CyberAP

    CyberAP Well-Known Member

    I just need to insert my code right where the template's contents end. For example at the end of extra.css template.
     
  4. EQnoble

    EQnoble Well-Known Member

    Well I haven't played with the TM yet but if I assume correct, to literally add content to the end of a template regardless what is already in the template you would need to just capture all text and then replace that with all of that captured text + what ever you are adding.


    If I am correct in thinking this will work...

    in the expression
    #.+#siu will literally capture everything

    in the replace
    $0 will put all that captured text back and then you can enter your data after that

    example
    $0

    .content2 {
    height:420px;
    }

    I need to play around with it still. Please let me know if that works for you
     
    CyberAP likes this.
  5. CyberAP

    CyberAP Well-Known Member

  6. EQnoble

    EQnoble Well-Known Member

    #(.+|)#siu

    this will work I think, lemme test it really quick

    Literally says anything or nothing
     
    CyberAP likes this.
  7. CyberAP

    CyberAP Well-Known Member

    Nope, still no luck with this. Fun thing that even none of the regex works with filled templates. I tried @Mike's code and it doesn't work too.

    Maybe there is a bug in beta 3.
     
  8. EQnoble

    EQnoble Well-Known Member

    It works for me...but the problem is that second expression will add it once if the template it blank and more if it is not.
     
    CyberAP likes this.
  9. CyberAP

    CyberAP Well-Known Member

    Oh, sorry, that's my mistake. I was doing a string replace...
    @Mike's code is working perfectly!

    Thanks again for your help!
     
  10. EQnoble

    EQnoble Well-Known Member

    This works inserting at the end of a template if there is content...and also will insert into a blank template


    #(.+|^\s*$)#siu

    I think you should use that...*if you add content to the template later I think it will add your replacement multiple times with just ^\s*$ (oddly I was testing the same regex and didn't check the link until after I tested this)


    *EDIT: I take that back , ^\s*$ alone will not add content if the extra.css is not blank which means if a person is using a style relying on this and adds content to the template the TM will not apply anymore
     
    Last edited: Jun 26, 2013

Share This Page