• 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

Chris D

XenForo developer
Staff member
#1
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?
 

-Ice-

Active member
#2
I know you can't do it with template hooks (you can only concatenate admin templates). There might be another way, though.
 
R

ragtek

Guest
#3
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)
 

Chris D

XenForo developer
Staff member
#4
If you have the add on that's great, if not then what you've said makes sense. I'll work through it. Cheers :)
 
R

ragtek

Guest
#8
Oh wow. That's pretty cool :D

Where did you find that?
XenForo_ViewAdmin_CssInternal::renderCss


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

XenForo developer
Staff member
#9
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

PreviewNotification2.PNG
 

Chris D

XenForo developer
Staff member
#10
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)
What is the admintemplate cache?

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

Chris D

XenForo developer
Staff member
#12
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.
 

Chris D

XenForo developer
Staff member
#13
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.