MyBB Community Forums

Full Version: Calling Table inside Template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a way to call this code using a global variable so I can pluck it into any theme/template and have it display using the code below. That way I can just edit the global variable each month and it would auto populate the changes to each template, depending on where I placed the function to call it. Is this doable? 



<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
<tr>
<td class="thead">
<div class="float_left"><strong>Community Stars - Apr '18</strong></div> 
</td>
</tr>
<tr>
<td class="trow2">
	<strong>‘Best’ Character</strong> – <a href="http://omniverse-rpg.com/showthread.php?tid=7358">Serraph Quarrere</a><br>
	<strong>‘Best’ Writer</strong> – <a href="http://omniverse-rpg.com/showthread.php?tid=???">Reece</a> <br>
	<strong>Most Helpful</strong> – <a href="http://omniverse-rpg.com/member.php?action=profile&uid=150">Kopaka</a><br>
	<strong>Rising Star</strong> – <a href="http://omniverse-rpg.com/showthread.php?tid=9763">Taloc</a><br>
	<strong>'Best' Story</strong> – <a href="http://omniverse-rpg.com/showthread.php?tid=9881">"The King and His Merry Men" (New Babylon)</a> <br>
	<strong>'Best' NPCs</strong> – <a href="http://omniverse-rpg.com/showthread.php?tid=XXXX">Yandere_Lover (Shantotto)</a><br>
	<strong>Purple Ribbon</strong> - <a href="http://omniverse-rpg.com/member.php?action=profile&uid=19">Trixie</a><br>
		</td>
</tr>
</table>

https://community.mybb.com/post-603543.html

So this is what I'm trying to do. I'm trying to call a template. I've altered the PHP and it's still not working. I'm assuming since we're a couple versions in the future that something has changed?
Put your code in a template as usual and then use the following code in your .php file:

eval("\$variablehere = \"".$templates->get("your_template_name_here")."\";"); 

Once you've done that add {$variablehere} to whichever template you want to call it in. It would be easier if you pasted your full code.
I use the PHP in Templates and Template Conditionals to do that. It's a dream!

https://community.mybb.com/thread-31860.html

For example, I have Global Templates called 'information_footer', 'information_sidebar', 'information_menu', etc. I change the global template, and where I want it to appear in the actual theme, I put "<template information_sidebar>"

EG, my Index template is:

<html>
<head>
<title>{$mybb->settings['bbname']}</title>
{$headerinclude}{$recentthread_headerinclude}
<script type="text/javascript">
<!--
    lang.no_new_posts = "{$lang->no_new_posts}";
    lang.click_mark_read = "{$lang->click_mark_read}";
// -->
</script>
</head>
<body>
{$header}
<br />
<template information_sidebar>	
<div class="forums" style="float: left; width: 76%;">{$forums}
</div>
<br class="clear" />
{$dvz_shoutbox}
{$footer}
</body>
</html>

Which means, whenever I update the global template 'information_sidebar' it's echoed on all my themes and I don't have to go from one theme to the next to update them all to read the same information.
(2018-06-10, 02:08 AM)Wires Wrote: [ -> ]Put your code in a template as usual and then use the following code in your .php file:

eval("\$variablehere = \"".$templates->get("your_template_name_here")."\";"); 

Once you've done that add {$variablehere} to whichever template you want to call it in. It would be easier if you pasted your full code.

I've done this entire process. Adding the code to index.php doesn't make the template callable inside a template. The code you're seeing is the code that I'm trying to call, but in template form. We list Community Stars each month and I'd like to edit a global template instead of going into the Index template for each theme and doing it manually. However, the quoted method hasn't worked. 

This is our Index template. It's kind of a mess. I inherited cleaning this up. Our themes were built for 1.8.7 so when we upgraded to 1.8.15, because our Admin CP was functionally broken it started breaking a lot of things. 

<html>
<head>
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-43611117-1', 'auto');
  ga('send', 'pageview');

</script>
<meta name="description" content="The Omniverse is a play-by-post roleplaying game in an original multiverse setting."/>
<meta name="keywords" content="rpg, roleplay, writing, roleplaying game, crossover, multiverse, play-by-post, PbP, omniverse, game, forum" />
<title>{$mybb->settings['bbname']} &bull; A Crossover Multiverse PbP RPG</title>
{$headerinclude}
<script type="text/javascript">
<!--
	lang.no_new_posts = "{$lang->no_new_posts}";
	lang.click_mark_read = "{$lang->click_mark_read}";
// -->
</script>
<style type="text/css">
.navigation {display:none;} /*Index only*/
</style>	
</head>
<body>
{$header}
	
<table width="100%" cellspacing="0" cellpadding="{$theme['tablespace']}" border="0">
<tr>
<td valign="top" width="78%">
	
{$inferno_shoutbox}
{$forums}
{$boardstats}

	
</td>
<td valign="top">
	
	<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
<tr>

	<td class="thead">
<div class="float_left"><strong>Community Stars - Apr '18</strong></div> 
</td>
</tr>
<tr>
<td class="trow2">
	{$communitystars}
	<strong>‘Best’ Character</strong> – <a href="http://omniverse-rpg.com/showthread.php?tid=7358">Serraph Quarrere</a><br>
	<strong>‘Best’ Writer</strong> – <a href="http://omniverse-rpg.com/showthread.php?tid=???">Reece</a> <br>
	<strong>Most Helpful</strong> – <a href="http://omniverse-rpg.com/member.php?action=profile&uid=150">Kopaka</a><br>
	<strong>Rising Star</strong> – <a href="http://omniverse-rpg.com/showthread.php?tid=9763">Taloc</a><br>
	<strong>'Best' Story</strong> – <a href="http://omniverse-rpg.com/showthread.php?tid=9881">"The King and His Merry Men" (New Babylon)</a> <br>
	<strong>'Best' NPCs</strong> – <a href="http://omniverse-rpg.com/showthread.php?tid=XXXX">Yandere_Lover (Shantotto)</a><br>
	<strong>Purple Ribbon</strong> - <a href="http://omniverse-rpg.com/member.php?action=profile&uid=19">Trixie</a><br>
		</td>
</tr>
	</table>


<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
<tr>
<td class="thead">
<div class="float_left"><strong>Latest Threads</strong></div> 
</td>
</tr>
<tr>
<td class="trow2">
<p><div class="latestthreads"></div></p>
<script type="text/javascript">
jQuery(function(){
jQuery(".latestthreads").load("{$mybb->settings['bburl']}/portal.php .latestthreads_portal");
});
</script>

		</td>
</tr>
</table>

	<br>

	<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
<tr>
<td class="thead">
<div class="float_left"><strong>Discord</strong></div> 
</td>
</tr>
<tr>
<td class="trow2">
				<iframe src="https://discordapp.com/widget?id=152984527176859658&theme=dark" width="200" height="500" allowtransparency="true" frameborder="0"></iframe>
		</td>
</tr>
</table>
	
	
  <br />	
	
</td>
</tr>
</table>
	
	
	
	
	
	<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
<tr><td class="thead"><strong>Affiliates</strong></td></tr>
<tr><td class="trow1">
	
	
	
	
	
	
<a href="http://www.rpgfix.com/" title="RPGfix"><img src="http://i.imgur.com/BshGflJ.gif" alt="RPGfix"/></a>
<a href="http://www.toprpsites.com/"><img src="http://www.toprpsites.com/images/extra/button2.gif" alt="Top RP Sites" /></a><img src="http://www.toprpsites.com/button.php?u=Helixagon&buttontype=text" alt="Top RP Sites" border="0" style="display: none;" width="1px" height="1px"/>
<a href="http://rpg-directory.com/" target="_blank"><img src="https://static18.icyboards.net/rpgdirectory/images/rpgdbutton1.png"  alt="RPG-D" title="RPG-Directory" border="0" /></a>
<a href="http://toprpgsites.gotop100.com/in.php?ref=605" target="_blank" rel="nofollow"><img src="http://toprpgsites.gotop100.com/lists/toprpgsites/custombanners/38579.png" border="0" width="88" height="31" alt="Top RPG Sites"> </a>
<a href="http://forumroleplay.gotop100.com/in.php?ref=431"><img src="http://forumroleplay.com/resources/images/site/links/88x31/88x31-vote-dark-gray.png" border="0" title="Forum Roleplay: Roleplay resources catering to play-by-post forum gamers and communities" alt="Forum Roleplay: Roleplay resources catering to play-by-post forum gamers and communities"></a>
<a href='http://landofavalon.com/' target='_blank' rel="nofollow"><img src='http://i283.photobucket.com/albums/kk284/AvalonReborn/Affiliates/Our%20Buttons/RedSmall_Alayel.gif' border='0' /></a>
<a href="http://unbound.b1.jcink.com/" rel="nofollow" target="_blank"><img src="http://i.imgur.com/lIvdp5J.png"></a>
<a href="http://narutobeginnings.forumsmotions.com/forum" rel="nofollow" target="_blank"><img src="http://i450.photobucket.com/albums/qq228/jcharles905/bannerfans_7281930.jpg"></a>
<a href="http://www.narutosaga.com/" rel="nofollow" target="_blank"><img src="http://i80.servimg.com/u/f80/13/07/69/12/button10.png" border="0" alt="Naruto Saga"></a>
<a href="http://magiworld.forumotion.com/" rel="nofollow" target="_blank"><img src="http://i.imgur.com/LdArOEO.png"></a> 
	
</td></tr>
</table><br>
	
	
	
	
	<div align=center><iframe src="http://www.top-site-list.com/vote-button/index.php?siteID=461934&amp;rank=1&amp;layout=s&amp;font=0&amp;textColor=dark&amp;buttonColor=grey&amp;" style="background:none; border:0; border:0; margin:0; padding:0; max-width:100%; width:250px; height:70px; "><a href="http://www.top-site-list.com"><img src="http://www.top-site-list.com/assets/img/tsl80.png" alt="Top Site Lists" /></a></iframe>
		
		<br>
		<iframe src="//www.facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2Fomniverserpg&amp;width&amp;height=62&amp;colorscheme=light&amp;show_faces=false&amp;header=true&amp;stream=false&amp;show_border=true" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:62px;" allowTransparency="true"></iframe></div>
	
	
	
	
	
<br class="clear" />
{$footer}
</body>
</html>

Thanks for the replies both of you. It's greatly appreciated.