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

Search and Replace

Discussion in 'XenForo Development Discussions' started by Mythotical, Mar 24, 2013.

  1. Mythotical

    Mythotical Well-Known Member

    I'm sure I used it before but can anyone recall the line of code to execute within a mod to replace a specific line within a template with a new line when installing the mod?

    Similar to vB's fine <xen:comment> and replace with <xen:comment>This goes here...
     
  2. cclaerhout

    cclaerhout Well-Known Member

    No, there's no helper to search&replace some text in templates. If you want to replace the XenForo Raw Code in template, use TMS, otherwise you can modify parsed template code with two of the three template listeners: one at the hook level, the other one at the template level once it has been parsed.

    In any cases, even with TMS, you can use direct text replacements (str_replace) or regex replacements (preg_replace).
     
  3. Mythotical

    Mythotical Well-Known Member

    I prefer not to use TMS.

    What is the process for search and replace at the template level after it has been parsed?
     
  4. tyteen4a03

    tyteen4a03 Well-Known Member

    I was looking for the same thing. I'm surprised this does not exist..
     
  5. cclaerhout

    cclaerhout Well-Known Member

    I told you, create a new listener "template_post_render" to target a whole template or "template_hook" to target the content of a hook. In both cases, the content will be already parsed. Then to modify the content just modify on the fly the variable $content (or $contents, depending on the callback signature)
    Basic example:
    PHP:
    $content str_replace('this was before''this is now'$content);
    Now don't forget, these change will be made when the page is loading, where as with TMS these changes will already be cached. Both methods are useful, all depend of what you want to do.
    When you can use TMS, just use it. It will save up some server resources.
     

Share This Page