This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » legacy support » symfony 1.2 » slot / partial / or component for container div
slot / partial / or component for container div [message #98298] Fri, 30 April 2010 02:56 Go to next message
smugford  is currently offline smugford
Messages: 99
Registered: November 2009
we have a container that needs to be reproduced over and over again in our site that is basically the same except for the header color.

Originally i had made it a partial and because of the size of the site it grew out of hand pretty quickly because it was one big switch/case statement that called different partials for the inner content of the container.

The code got out of hand so what i started to do was the following...

I build a component called container.

Then i build a slot with the content that I want to be inside of that container

Then build out a container with the following code

<?php slot('slotExample'); ?>
	Content of the Container
<?php end_slot(); ?>

<?php $ContainerWidth = sfConfig::get('app_containerWidths_width1');?>
<?php $settings = array('width' => $ContainerWidth, 'color' => 'blue', 'expand' => false); ?>
<?php $content = array('ContentId'=> 10, 'current_page' => $current_page, 'content' => $content,
                            'ContainerTitle' => "Content Title"); ?>
<?php include_component('default','container', array('content' => $content, 'settings' => $settings)); ?> 

that builds out this...

<div class="<?php echo $layout_class; ?>" style="clear:left;width:<?php echo $container_width; ?>px;z-index:0;">    
    <div style="width:<?php echo $header_container_width; ?>;">
        <div class="<?php echo $left_header_color; ?>" style="">&nbsp;</div>
            <div class="<?php echo $middle_header_color; ?>" style="width:<?php echo $header_middle_width;?>px;">
            	Default Header Content 
        <div class="<?php echo $right_header_color; ?>">&nbsp;</div>
    <div id="<?php echo $ContentId; ?>" style="height:<?php echo $container_height;?>px;width:<?php echo $content_width; ?>px;margin-bottom:<?php echo $bottom_margin; ?>px;clear:left;" class="<?php echo $ContentClass; ?>">
		switch (true): 
			case ($ContentId == 10):
				include_slot('exampleSlot1') ;
			case ($ContentId == 20):
					include_slot('exampleSlot2') ;
				echo "<strong>" . $content . "</strong>" ;
</div><!-- close item page container -->

so i end up with something similar to this...


In the component I determine if it is blue, or green, or whatever the header and border colors are suppose to be.

This is the only way i could figure out how to get the inner content of the slot inside of the same style of container without having to copy and paste the container div code over and over again.

so my question is...

Is this the right use of a slot?

and if not what is the correct (or a better way) to accomplish what i am trying to do which is not have to repeat the code for building the container.

Thanks in advance.

  • Attachment: Drawing1.jpg
    (Size: 13.31KB, Downloaded 719 time(s))

Re: slot / partial / or component for container div [message #98332 is a reply to message #98298 ] Sat, 01 May 2010 02:42 Go to previous messageGo to next message
smugford  is currently offline smugford
Messages: 99
Registered: November 2009

Does the question not make sense? I'm not 100% sure if it is worded correctly so let me know if it doesn't make any sense.

I really need to know if i'm way off base on this one or not.

Thanks Smile
Re: slot / partial / or component for container div [message #98496 is a reply to message #98332 ] Tue, 04 May 2010 14:55 Go to previous message
weaverryan  is currently offline weaverryan
Messages: 781
Registered: November 2007
Location: Nashville, TN
Faithful Member

Hey Scott-

Yes, your situation isn't too strange, but you do have quite a customized area and so doing that with as little complexity is difficult.

I have a project where I use the same markup (an internal box with a thin left content and large right content) in many places in the site. Like you, I didn't want to be repeating this markup in multiple places.

You can feel good that my solution was very simliar to yours - so either you're right, or at least we're wrong together Smile. I defined my two areas in two different slots, and then included a partial that used those slots. It's not EXACTLY the way that slots were meant to work, but pretty close. In fact, I'd say the only potential difference or problem you may run into is the fact that each slot was really designed to be used only once on a page. In my project, this was the case. If you use the same slot in multiple places, you may define it in one place and be surprised when it pops up elsewhere Smile

Ryan Weaver
Previous Topic:sfValidatorChoice invalid - (WITH multiple true)
Next Topic:using CASE WHEN ELSE in Doctrine
Goto Forum:

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software