Class Template and variables

Discussion forum for MOD Writers regarding MOD Development.
Locked
r9skull
Registered User
Posts: 13
Joined: Sun Feb 07, 2010 11:41 am
Location: Poland
Contact:

Class Template and variables

Post by r9skull »

Hi! I'm using class Template to show some variables on board. My code:

Code: Select all

if(is_array($tags))
	{
		foreach($tags as $kupa => $pupa)
		{
			$template->assign_block_vars('tagiii', array(
			    'FOO' => $pupa,
			));
		}
	}
In cache file it looks like:

Code: Select all

<?php $_tagiii_count = (isset($_postrow_val['tagiii'])) ? sizeof($_postrow_val['tagiii']) : 0;if ($_tagiii_count) {for ($_tagiii_i = 0; $_tagiii_i < $_tagiii_count; ++$_tagiii_i){$_tagiii_val = &$_postrow_val['tagiii'][$_tagiii_i]; ?>

		<?php echo $_tagiii_val['FOO']; ?>
		<?php }}

[...]
And my array $_postrow_val['tagiii'] doesn't exist :( What I'm doing wrong?

@edit: My HTML code:

Code: Select all

<!-- BEGIN tagiii -->
		{tagiii.FOO}
<!-- END tagiii -->
Image
User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: Class Template and variables

Post by Erik Frèrejean »

Are you sure that the loop is executed?
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)
r9skull
Registered User
Posts: 13
Joined: Sun Feb 07, 2010 11:41 am
Location: Poland
Contact:

Re: Class Template and variables

Post by r9skull »

Erik Frèrejean wrote:Are you sure that the loop is executed?
Yes, because

Code: Select all

$template->assign_var('FOO', $foo);
work. Also work:

Code: Select all

$template->assign_vars(array(
    'FOO' => $foo,
    'BAR' => $bar,
    'BAZ' => $baz
));
Image
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52001
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Class Template and variables

Post by Brf »

What do those have to do with your loop executing?
r9skull
Registered User
Posts: 13
Joined: Sun Feb 07, 2010 11:41 am
Location: Poland
Contact:

Re: Class Template and variables

Post by r9skull »

I getting some data from database and I sending it to template. I checked data couple times - I'm sure that data are correct.
Image
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52001
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Class Template and variables

Post by Brf »

That still does not answer the question of whether $tags is an array, or your loop is executing.
r9skull
Registered User
Posts: 13
Joined: Sun Feb 07, 2010 11:41 am
Location: Poland
Contact:

Re: Class Template and variables

Post by r9skull »

Yes, it is array. This code:

Code: Select all

if(is_array($tags))
   {
      foreach($tags as $kupa => $pupa)
      {
         $template->assign_block_vars('tagiii', array(
             'FOO' => $pupa,
         ));
var_dump($pupa);
      }
   }
exit;
Show me $pupa. So something is wrong with $template->assign_block_vars() :(

@Brf: stop using Google Translate plz :mrgreen:
Image
ToonArmy
Former Team Member
Posts: 4608
Joined: Sat Mar 06, 2004 5:29 pm
Location: Worcestershire, UK
Name: Chris Smith
Contact:

Re: Class Template and variables

Post by ToonArmy »

The 'tagiii' block is nested inside the phpBB 'postrow' block. ;)

If the 'tagiii' block should be nested inside the 'postrow' block you need to use $template->assign_block_vars('postrow.tagiii', ...)
Chris SmithGitHub
r9skull
Registered User
Posts: 13
Joined: Sun Feb 07, 2010 11:41 am
Location: Poland
Contact:

Re: Class Template and variables

Post by r9skull »

ToonArmy wrote:The 'tagiii' block is nested inside the phpBB 'postrow' block. ;)

If the 'tagiii' block should be nested inside the 'postrow' block you need to use $template->assign_block_vars('postrow.tagiii', ...)
You are my hero! Thanks! :mrgreen:
Image
r9skull
Registered User
Posts: 13
Joined: Sun Feb 07, 2010 11:41 am
Location: Poland
Contact:

Re: Class Template and variables

Post by r9skull »

My hero, what can I do when i don't want postrow.tagii? :mrgreen: Just

Code: Select all

$template->assign_block_vars('tags', array(
Image
ToonArmy
Former Team Member
Posts: 4608
Joined: Sat Mar 06, 2004 5:29 pm
Location: Worcestershire, UK
Name: Chris Smith
Contact:

Re: Class Template and variables

Post by ToonArmy »

r9skull wrote:My hero, what can I do when i don't want postrow.tagii? :mrgreen: Just

Code: Select all

$template->assign_block_vars('tags', array(
Either move the <!-- BEGIN tags --> outside the postrow block, or if that is not possible use <!-- BEGIN !tags -->
Chris SmithGitHub
r9skull
Registered User
Posts: 13
Joined: Sun Feb 07, 2010 11:41 am
Location: Poland
Contact:

Re: Class Template and variables

Post by r9skull »

ToonArmy wrote: Either move the <!-- BEGIN tags --> outside the postrow block, or if that is not possible use <!-- BEGIN !tags -->
Thanks a lot - that should be in DOCS: http://wiki.phpbb.com/display/MODDOCS/T ... ate+syntax
Image
Locked

Return to “[3.0.x] MOD Writers Discussion”