[Chameleon] Server side include?

pxniw pxniw pxniw69 at yahoo.com
Tue Jul 6 17:49:34 EDT 2004


Ok here is the code:
(No performance hit noted btw)
and works great. ;)

Start Code

// Start ADDED by PXNIW (Wanted to parse $$ tags
before ## tags
// replace all [$something$] to the correct url var
value
// This is duplicate code from below so $$ parses
before ##
        $nPos = strpos($this->mszTemplate, "[$");
        while($nPos !== false)
        {
            $nEndPos = strpos($this->mszTemplate,
"$]", $nPos);
            $szTag = substr($this->mszTemplate, $nPos,
$nEndPos-$nPos+2);

            if
(isset($oApp->moHttpFormVars->maszVars[strtoupper(substr($szTag,
2, -2))]))
                $this->mszTemplate =&
str_replace($szTag, 
                       
$oApp->moHttpFormVars->maszVars[strtoupper(substr($szTag,
2, -2))],
                        $this->mszTemplate);
            $nPos = strpos($this->mszTemplate, "[$",
$nPos+2);
        }
// END ADDED by PXNIW

        // First, include all files to include.
        $nPos = strpos($this->mszTemplate, "[#");
        while ($nPos !== false)
        {
            $nEndPos = strpos($this->mszTemplate,
"#]");

            if ($nEndPos === false)
                break;

            $szTemplateName =
substr($this->mszTemplate, $nPos+2, $nEndPos-$nPos-2);

            // Make a copy of the current teplate
            $szTemplate = $this->mszTemplate;

            $oApp->CWCLoadTemplate($szTemplateName);

            $this->mszTemplate =&
str_replace("[#$szTemplateName#]", $oApp->mszTemplate,
$szTemplate);

            $nPos = strpos($this->mszTemplate, "[#");
        }

        // Then, replace all [$something$] to the
correct url var value
        $nPos = strpos($this->mszTemplate, "[$");
        while($nPos !== false)
        {
            $nEndPos = strpos($this->mszTemplate,
"$]", $nPos);
            $szTag = substr($this->mszTemplate, $nPos,
$nEndPos-$nPos+2);

            if
(isset($oApp->moHttpFormVars->maszVars[strtoupper(substr($szTag,
2, -2))]))
                $this->mszTemplate =&
str_replace($szTag, 
                       
$oApp->moHttpFormVars->maszVars[strtoupper(substr($szTag,
2, -2))],
                        $this->mszTemplate);
            $nPos = strpos($this->mszTemplate, "[$",
$nPos+2);
        }

        if (strlen($this->mszTemplate) == 0)
            return 0;

        $this->maszElements = array();
        $this->maszPlaceholders = array();

        $this->mszTemplate = preg_replace_callback(
$this->mszPattern,
                    array( &$this, "ParseCallback" ),
$this->mszTemplate );

        return $this->NumElements();
    }

End Code




--- Julien-Samuel Lacroix <jlacroix at dmsolutions.ca>
wrote:
> 
> > So how do I include my include with my include
> (That
> > sounds kinda cool ;) )
> > 
> > I tried this:
> >
>
[#http://www.test.com/cgi-bin/test.cgi?fruit=[$NAME_OF_FRUIT$]#]
> > 
> > It won't parse [$NAME_OF_FRUIT$] inside "##"
> > I tried several different ways, but could not get
> it
> > to work.
> 
> This can't work right now because the chameleon
> preprocessor parse [##] 
> tags before [$$] tags. The reason is simple. This
> way you can include 
> [$$] in components added by [##] tags. If you want
> to change this 
> behavior, look in the TemplateParser.php file 
> (chameleon/htdocs/TemplateParser.php) for the
> Parser() function. You 
> will see that the first thing that is done in this
> function is the 
> replacement of [##] tags and then the [$$] tags.
> Maybe you can invert 
> them. Or parse for [$$], then for [##] and again for
> [$$] to replace the 
> newly added tags. But this can have a little impact
> on performance.
> 
> Let us know what you have done and the impact on
> performance. :)
> 
> Thanks
> Julien
> 
> 
> 
> -- 
>
------------------------------------------------------------
> Julien-Samuel Lacroix           
> jlacroix at dmsolutions.ca
> DM Solutions Group              
> http://www.dmsolutions.ca/
>
------------------------------------------------------------
> 



	
		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 


More information about the Chameleon mailing list