TemplatePower Forum Forum Index TemplatePower Forum
Ask your question about TemplatePower here!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

import value into templatepower for use

 
Post new topic   Reply to topic    TemplatePower Forum Forum Index -> Coding Help
View previous topic :: View next topic  
Author Message
darth oinker



Joined: 13 Mar 2006
Posts: 3
Location: United States

PostPosted: Tue Mar 14, 2006 3:59 am    Post subject: import value into templatepower for use Reply with quote

I hope this doesn't step on anyones toes, i'm surely not trying to take over or continue development or anything like that, i just altered it to be able to do what i needed and since i'm not sure if anyone else has done this or if it was on the previous boards before the hack, but in case it wasn't or anyone is interested i just hacked this little bit of code together to do simple variable insertion from a template for use in the php.

in the TemplatePower.inc.php file

in this function
Code:
    function __parseTemplate( $tplvar, $blockname, $initdev )


you'll have
Code:
        while( $index < $this->{$tplvar}["size"] )
        {
           
            if ( preg_match('/<!--[ ]?(START|END) IGNORE -->/', $this->{$tplvar}["content"][$index], $ignreg) )
            {
                if( $ignreg[1] == 'START')
                {
                    //$ignore = true;
                         array_push( $this->ignore_stack, true );
                }
                else
                {
                    //$ignore = false;
                         array_pop( $this->ignore_stack );
                }
         
            }
            else



simply add the indicated content below in the proper place

Code:
        while( $index < $this->{$tplvar}["size"] )
        {
//from here           
if ( preg_match('/<!-- [ ]?(VAR) : (.+)-->/', $this->{$tplvar}["content"][$index], $valregs) )
            {
                     $value = explode("=",$valregs[2]);
                     $name = $value[0];
                     $val = $value[1];
                     $this->{$name} = $val;
            }//to here      
            
      
            if ( preg_match('/<!--[ ]?(START|END) IGNORE -->/', $this->{$tplvar}["content"][$index], $ignreg) )
            {
                if( $ignreg[1] == 'START')
                {
                    //$ignore = true;
                         array_push( $this->ignore_stack, true );
                }
                else
                {
                    //$ignore = false;
                         array_pop( $this->ignore_stack );
                }
         
            }
            else


and that will allow you to insert data from the tpl file with something like

Code:
 <!--  VAR : columns=4 -->


i found this as an easy way to create multi-columned tables in different site skins that required a different number of columns.

I've also got another mod that is called assignAppend that lets you concatenate content to a template variable -- this one was rather easy to implement so if anyone is interested just let me know. It's useful for site skins where you have javascript for a specific skin and don't want to bog down the skins that don't need that javascript - of course this is the only thing i've found that i need it for, but i'm sure someone else could come up with other reasons to use it.
_________________
Darth Oinker
http://www.simplyundeniable.com - HP fanfiction site
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    TemplatePower Forum Forum Index -> Coding Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group