2014-12-18, 09:21 AM
2014-12-18, 09:27 AM
(2014-12-18, 09:21 AM)Clear Wrote: [ -> ]As in the subject, is it possible call a template made by my plugin inside another template made by my plugin?
Yes.
(2014-12-18, 09:21 AM)Clear Wrote: [ -> ]I tried some codes but they not work!
How exactly does this information help us with noticing what your problem is? Posting what you tried would be a better idea..
2014-12-18, 09:48 AM
(2014-12-18, 09:27 AM)Destroy666 Wrote: [ -> ](2014-12-18, 09:21 AM)Clear Wrote: [ -> ]As in the subject, is it possible call a template made by my plugin inside another template made by my plugin?
Yes.
(2014-12-18, 09:21 AM)Clear Wrote: [ -> ]I tried some codes but they not work!
How exactly does this information help us with noticing what your problem is? Posting what you tried would be a better idea..
Ok, thank you for your support. Before to post my code, I want to let you know what I want to do.
My plugin has a template called in the index page: {$mynews}. In this template there is some calls to database, but the code is the following:
<ul>
<li>hello</li>
</ul>
As you can see, I want to make a foreach cicle but only for this code:
<li>hello</li>
So I want to make this "system":
Index template:
{$header}
{$myplugin}
{$forums}
myplugin template:
<ul>
{$myplugin_foreach}
</ul>
myplugin_foreach template:
<li>hello</li>
I tried this:
<?php
$plugins->add_hook('index_start', 'mynews_index');
$plugins->add_hook('index_start', 'mynews_index_foreach');
function mynews_activate() {
global $mybb, $db;
//.....
$insert = array(array(
"title" => 'mynews_index',
"template" => $db->escape_string('
<ul class="mynews_cards">
{$mynews_index_foreach}
<hr style="clear: both; visibility: hidden;">
</ul>'),
"sid" => "-1",
"dateline" => TIME_NOW
), array(
"title" => 'mynews_index_foreach',
"template" => $db->escape_string('
<li>
<ul class="mynews_topic">
<li>
Lorem psum dolor sit amet
</li>
<li>
Lorem ipsum dolor sit amet, consectetur adipisci elit, sed eiu...
</li>
</ul>
<div class="mynews_date">
<span>12</span>
<span>Dec</span>
</div>
<div class="mynews_more">
<a href="#">read more</a>
</div>
</li>'),
"sid" => "-1",
"dateline" => TIME_NOW
));
$db->insert_query_multiple('templates', $insert);
//........
}
//other functions
function mynews_index_foreach() {
global $mybb, $db, $lang, $templates, $mynews_index_foreach, $theme;
eval("\$mynews_index_foreach = \"".$templates->get('mynews_index_foreach')."\";");
}
function mynews_index() {
global $mybb, $db, $lang, $templates, $mynews, $theme, $mynews_index_foreach;
eval("\$mynews = \"".$templates->get('mynews_index')."\";");
}
?>
2014-12-18, 10:01 AM
1. Why are you separating it into 2 functions?
2. There is no loop in any of them..
The code doesn't make any sense now. You need something like this:
2. There is no loop in any of them..
The code doesn't make any sense now. You need something like this:
function mynews_index() {
global $templates, $mynews;
foreach($something as $sth) // or for, while, whatever
{
eval('$mynews_index_foreach .= "'.$templates->get('mynews_index_foreach').'";');
}
eval('$mynews = "'.$templates->get('mynews_index').'";');
}
2014-12-18, 10:06 AM
(2014-12-18, 10:01 AM)Destroy666 Wrote: [ -> ]1. Why are you separating it into 2 functions?
2. There is no loop in any of them..
The code doesn't make any sense now. You need something like this:
function mynews_index() { global $templates, $mynews; foreach($something as $sth) // or for, while, whatever { eval('$mynews_index_foreach .= "'.$templates->get('mynews_index_foreach').'";'); } eval('$mynews = "'.$templates->get('mynews_index').'";'); }
You are right! I'll try this and I will let you know if it works! Thank you!
P.S. for the loop I know, I would put it after that I could call the template
Ok, I tried this but it not works @Destroy666
function mynews_index() {
global $mybb, $db, $lang, $templates, $mynews, $theme;
eval("\$mynews = \"".$templates->get('mynews_index')."\";");
eval("\$mynews_index_foreach = \"".$templates->get('mynews_index_foreach')."\";");
}
Edit:
Ok, I forgot to call the mynews_index_foreach before to mynews_index... Now it works, thank you! ^^