Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Pointing Blocks dynamic

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
ne0hype
Smarty Rookie


Joined: 08 May 2010
Posts: 14

PostPosted: Sun Jan 06, 2013 12:59 pm    Post subject: Pointing Blocks dynamic Reply with quote

Hi guys,

it's me again... Smile

i have a pagelayout like this:


i have some, i call it "gadgets". that are small templatefiles. for example: a login field, a poll, a small calander.
All this templates have no "block" tag in it for a spezial reason.

i want to put this gadgets in all of the pageareas.
so i have done like this:

Code:
public function templateInheritanceMaker($templateFile, $block, $append = false) {
       
        if(file_exists($templateFile)){
                       
            $templateSource = base64_encode('{block name='.$block.' append}'.file_get_contents($templateFile).'{/block}');
           
            $inheritance = '|eval:base64:'.$templateSource; 
       
        }else{
            throw new FatalException($block.' Template '.$templateArray[1].' nicht vorhanden');
        }   
       
        return $inheritance; 
    }


now i read, that the template, given as string, will always compiled...

so is that any other solutions to put templates dynamic together?

Thanks
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Jan 06, 2013 6:37 pm    Post subject: Reply with quote

Yes the "eval" resource does compile the template string each time it gets called.

But you can use the "string" resource instead of "eval". It does store the compiled string and reuse it on later calls. The only drawback is that a modified string will create a different compiled template file and the old version will not be deleted automatically because the string content is encoded in the compiled filename.
Back to top
View user's profile Send private message
ne0hype
Smarty Rookie


Joined: 08 May 2010
Posts: 14

PostPosted: Sun Jan 06, 2013 11:36 pm    Post subject: Reply with quote

Hello,

thanks fo your answer...

but the main problem is that the script have to get the gadget template source every time to find the compiled file

for example:
Code:
$foo = '{block name=gadgetsLeft append}'.file_get_contents('templates/gadgets/1.tpl').'{/block}';
$bar = '{block name=gadgetsLeft append}'.file_get_contents('templates/gadgets/2.tpl').'{/block}';

$smarty->display('extends:index.tpl|file:content/content1.tpl|string:'.$foo.'|string:'.$bar);


this works fine and a compiled file is written. but i have to get the source of the template by file_get_content each time...

i don't know if there is an other solutions for this overhead.

ps: vielleicht kannst du (uwe) das ganze in der Deutsche Forum packen und auch auch deutsch anworten Smile
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Jan 07, 2013 8:05 pm    Post subject: Reply with quote

Normalerweise würde man die {block} mit ihrem gadget Namen in das template file packen und entsprechende {block} tags in index.tpl verwenden.

Ich weiß nicht warum Du dies nicht machst, sondern dynamisch Block Namen wie gadgetsLeft vergeben willst. Du kommst dann nicht um file_get_contents vorbei.

Auf jeden Fall hat Dir die string Resource eine extrem verbesserte Performance gebracht.
Back to top
View user's profile Send private message
ne0hype
Smarty Rookie


Joined: 08 May 2010
Posts: 14

PostPosted: Mon Jan 07, 2013 10:26 pm    Post subject: Reply with quote

Hallo Uwe,

der Grund warum ich den Block Tag nicht in das Kind-Template packt ist der, das ich das Kind-Template z.b. mal in den rechten oder in den linken Bereich haben möchte. Ich möchte also das Gadget in verschiedenen Blocks (gadgetLeft, gadgetRight oder auch gadgatBottom) platzieren ohne jedes mal eine neues Kind-Template zu erstellen.


Ich hatte das Ganze vorher über die include Methode gelöst.

index.tpl
Code:
{foreach $gadgets->getGadgets('right') as $gadget}
                              {include file=$gadget->getTemplate()}
                            {/foreach}


Ich weiss nicht ob das die Bessere Methode ist als das ich das Kind-Template über file_get_contents() erst hole und dann ein String daraus bilde.

Danke..
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jan 08, 2013 7:41 pm    Post subject: Reply with quote

Warum machst Du nicht in 1.tpl {block name='gadget1'} ... {block} und in 2.tpl {block name='gadget2'} ... {block}

In index.tpl bestimmst du dann mit
{block name='gadget1'}{block}
{block name='gadget2'}{block}

wo die Gadgets hin sollen.

So wäre es im Sinne des Erfinders und Du hast auch die Trennung von PHP und Layout in Templates.

Die Child-Templates definieren so nur die Inhalte der Gadgets und im Parent bestimmst Du die Position.
Back to top
View user's profile Send private message
ne0hype
Smarty Rookie


Joined: 08 May 2010
Posts: 14

PostPosted: Tue Jan 08, 2013 10:49 pm    Post subject: Reply with quote

Aber dann ist doch da nichts mehr dynamisch....

Dann ist das "gadget1" immer an die position des Blocks im index.tpl gebunden.

Ich möchte aber die Sammlung von Gadgets frei positionieren können.
Frei im Sinne von, ich hab vordefinierte Bereiche.

So wie du es geschrieben hast, habe ich erst mal eine beschränkte Anzahl von Gadgets im index.tpl und zweitens müsste ich um die Position wechseln zu wollen die Kind-Templates ändern.

Aber vielleicht will der Kunde per Drag & Drop die Gadgets in andere Bereiche verschieben und nach einem refresh sind diese dort positioniert.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jan 08, 2013 11:42 pm    Post subject: Reply with quote

Also wenn der User die Gadgets hin und her schieben können soll ist Template-Inheritance vielleicht doch der falsche Ansatz und

Code:
{foreach $gadgets->getGadgets('right') as $gadget}
                              {include file=$gadget->getTemplate()}
                            {/foreach}


die bessere Methode.
Back to top
View user's profile Send private message
ovnn
Smarty Regular


Joined: 14 Apr 2010
Posts: 82
Location: Germany

PostPosted: Wed Jan 09, 2013 9:22 am    Post subject: Reply with quote

ich habe hier für eine Seite ein Gittersystem 4 spalten und beliebig Zeilen darin kann der User seine boxen anordnen. In der DB Speicher ich die spalte und Zeile.

im Template gehe ich dann die Spalten durch und gebe dort die Boxen aus die ich aus der DB für diese Spalte stehen habe.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German 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
Protected by Anti-Spam ACP