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

Render public templates in Admin CP

Discussion in 'XenForo Development Discussions' started by Chris D, Jul 18, 2012.

  1. Chris D

    Chris D XenForo Developer Staff Member

    Going to be vague but theoretically would it be possible to render specific public templates in the Admin CP using an add on?

    Haven't looked into it yet, but if so, how?
  2. -Ice-

    -Ice- Active Member

    I know you can't do it with template hooks (you can only concatenate admin templates). There might be another way, though.
  3. ragtek

    ragtek Guest

    fetch the compiled template code from xf_template_compiled

    set it to the admintemplate cache
    create a new admintemplate instance with your public template name and the view params
    get the required css templates
    add the public css.php call to output

    that's it in theory:) (and it's working, because i've done this in the past, have to check if i can find the addon)
    Adam Howard likes this.
  4. Chris D

    Chris D XenForo Developer Staff Member

    If you have the add on that's great, if not then what you've said makes sense. I'll work through it. Cheers :)
  5. Chris D

    Chris D XenForo Developer Staff Member

    I posted this in the wrong forum :oops:

    Should have been in development discussions.
  6. ragtek

    ragtek Guest

    Just seen that you can use

    <xen:require css="public:cssTemplateName" />

    for css template
    Jake Bunce and Chris D like this.
  7. Chris D

    Chris D XenForo Developer Staff Member

    Oh wow. That's pretty cool :D

    Where did you find that? You're a genius.
  8. ragtek

    ragtek Guest


    there you can see that xf is making the same thing as i in post 3
    sadly it's only available for the css templates in the core.

    but i had a play with my "instructions" from post3 and it's working
    Chris D likes this.
  9. Chris D

    Chris D XenForo Developer Staff Member

    Yeah, turns out the more I thought about it I didn't need a public HTML template at all.

    What I needed was some public CSS including contents of one of my own stylesheets and EXTRA.css.

    It never occurred to me to just call the public css.php - it works perfectly!

    Thank you for the advice :D Even though I asked the wrong question, you provided an answer that lead me to the solution - and the original answer to the question is bound to be useful in the future.

    Pulling the public CSS files through to the Admin CP will now allow people using my Notifications add-on to preview exactly how they look before they submit their changes to be viewable in the front end :D

    HenrikHansen likes this.
  10. Chris D

    Chris D XenForo Developer Staff Member

    What is the admintemplate cache?

    I can't find this, I assumed it was a database table.
  11. ragtek

    ragtek Guest

    XenForo_Template_Admin::setTemplate($templateName, $templateCompiled);
  12. Chris D

    Chris D XenForo Developer Staff Member

    Thank you so much for this, it has been a huge help.

    I can now print_r($myTemplate) and see the raw output of my template - so that side of things is working.

    I do setTemplate and when I try to then do $contents .= $template->create('my_template') in a hook, I get an error.

    Similar to the errors mentioned in this post: http://xenforo.com/community/thread...e-when-injecting-code-inside-templates.30999/

    Any ideas what I might have missed? Or a code example?

    Cheers, appreciate your help.
  13. Chris D

    Chris D XenForo Developer Staff Member

    I have realised my mistake.

    The database query I used to fetch the template returns the result as an array :oops:

    I now do:

    $template->setTemplate('myTemplate', $result['template_compiled']);

    And that works :D

    Thanks ragtek.

Share This Page