SlideShare a Scribd company logo
Open-Source PHP5 MVC Framework
                                                                                                                                            Agile Development



VIEW
PARTIALS, COMPONENTS, SLOTS and COMPONENT SLOTS
                                      PARTIALS                                                                                   SLOTS
  Reusable chunk of template code. A template can include partials whether                  A placeholder that you can put in any of the view elements (in the layout,
  it is in the same module, in another module, or in the global templates/                  a template, or a partial). Filling this placeholder is just like setting a
  directory. Partials have access to the usual symfony helpers and template                 variable. The filling code is stored globally in the response, so you can
  shorcuts, but not to the variables defined in the action calling it, unless               define it anywhere (in the layout, a template, or a partial). Slots are very
  passed explicitly as an argument.                                                         useful to define zones meant to display contextual content.

                   Article Detail     Best Articles     Lastest Articles                         Template                     Layout                        Layout
                                                                                                                      Slot                           Slot
                   Article Partial    Article Partial
                                      Article Partial
                                                        Article Partial
                                                        Article Partial                           Slot 1
                                                                                                               +       1
                                                                                                                                Template
                                                                                                                                              =       1
                                                                                                                                                              Template


                                                                                                                              Slot 2                        Slot 2
                                      Article Partial   Article Partial                           Slot 2


   USING A PARTIAL                                                                          USING A SLOT
  Create a file named _<partial_name>.php, that contains the partial, in:                   To define a slot in a template:
  <myproject>/apps/<myapp>/modules/<mymodule>/templates/                                    Each template has the ability to define the contents of a slot.
  To include a partial:                                                                     As slots are meant to hold HTML code, just write the slot code between
                                                                                            a call to the slot(<slot_name>) and end_slot() helpers.
  <?php include_partial('<module>/<partial_name>’, array('<var>'=>$<var>)) ?>
                                                                                             E.g.: Overriding the 'sidebar' slot content in a template
  Global partials:                                                                                <?php slot('sidebar') ?>
  Should be in: <myproject>/apps/<myapp>/templates/                                                  <!-- custom sidebar code for the current template-->
                                                                                                     <h1>User details</h1>
  To include a global partial:                                                                       <p>name: <?php echo $user->getName() ?></p>
  <?php include_partial('global/<partial_name>’) ?>                                                  <p>email: <?php echo $user->getEmail() ?></p>
                                                                                                  <?php end_slot() ?>

                                                                                            To include a slot:
                                     COMPONENTS
                                                                                             <?php include_slot('<slot_name>’) ?>
  A partial with a logic behind.          Template
  Is like an action, it can pass        Headlines Sidebar
                                                                                            To verify if a slot is defined:
  variables to a template                                                                    <?php has_slot('<slot_name>’) ?>
  partial, except it's much
  faster. The logic is kept in a                                                            The has_slot() helper returns true if the slot has been defined before,
                                                     Headlines Component     Logic          providing a fallback mechanism.
  components.class.php file
  in the actions/ directory,
                                                       Headlines Partial     Presentation    E.g.: Including a 'sidebar' slot in the layout
  and the template is a regular partial.
  You can include components in components,                                                       <div id="sidebar">
  or in the global layout, as in any regular template.                                              <?php if (has_slot('sidebar')): ?>
                                                                                                          <?php include_slot('sidebar') ?>
   USING A COMPONENT                                                                                <?php else: ?>
                                                                                                          <!-- default sidebar code -->
  Presentation:                                                                                           <h1>Contextual zone</h1>
  Create a file named _<component_name>.php, in:                                                          <p>This zone contains links and information relative to the
  <myproject>/apps/<myapp>/modules/<mymodule>/templates/                                                   main content of the page.</p>
   ...                                                                                              <?php endif; ?>
     <?php foreach($news as $headline): ?>                                                        </div>
       <li>
        <?php echo $headline->getPublishedAt() ?>
        <?php echo link_to($headline->getTitle(),'news/show?id='.$headline->getId()) ?>
       </li>
     <?php endforeach ?>
                                                                                                                        COMPONENT SLOTS
   ...                                                                                      A component which varies according to the module calling it. Component
  Logic:                                                                                    slots are named placeholders that you can declare in the view elements.
  Create a file named components.class.php, that is the class inheriting                    For a component slot, the code results from the execution of a component
  from sfComponents, in:                                                                    and the name of this component comes from the view configuration.
  <myproject>/apps/<myapp>/modules/<mymodule>/actions/                                      Useful for breadcrumbs, contextual navigations and dynamic insertions.
  E.g.: <?php                                                                               USING A COMPONENT SLOT
        class newsComponents extends sfComponents{
           public function executeHeadline(){                                               To set a component slot placeholder:
              $c = new Criteria();
              $c->addDescendingOrderByColumn(NewsPeer::PUBLISHED_AT);                        <?php include_component_slot('<component_slot_name>’) ?>
              $c->setLimit(5);
              $this->news = NewsPeer::doSelect($c);                                         To define a default component slot in the view.yml (located in
           }                                                                                <myapp>/config):
        }
                                                                                               default:
                                                                                                components:
  To call a component:
                                                                                                 <component_slot_name>: [<module_name>, <partial_name>]
  include_component('<module>', '<component_name>’, array('<var>'=>$<var>))
   <?php include_component('news', 'headlines') ?>                                          This will call the execute<partial_name> method of the
                                                                                            <module_name>Components class in the components.class.php located
  Components accept additional parameters in the shape of an associative                    in <module_name> module, and will display the _<partial_name>.php
  array. The parameters are available to the partial under their name, and                  located in:
  in the component via the $this object:                                                    <myproject>/apps/<myapp>/modules/<module_name>/templates/
  E.g.: call to the component:
        <?php include_component('news', 'headlines', array('foo' => 'bar')) ?>              To disable a component slot in view.yml (located in <myapp>/config):
        in the component itself:                                                               all:
        <?php echo $this->foo; ?>       // 'bar'                                                components:
        in the _headlines.php partial:                                                            <component_slot_name>: []
        <?php echo $foo; ?>            // 'bar’


http://andreiabohner.wordpress.com                                                                         This cheat-sheet is not an official part of the symfony documentation

More Related Content

DOC
Apex cheat sheet 3
PDF
Dynamic website
PDF
Start using PHP 7
PPTX
PHP Course (Basic to Advance)
PDF
Cake Php 1.2 (Ocphp)
PPTX
Programming Fundamentals lecture 5
PDF
Php web development
PDF
Introduction to JSP
Apex cheat sheet 3
Dynamic website
Start using PHP 7
PHP Course (Basic to Advance)
Cake Php 1.2 (Ocphp)
Programming Fundamentals lecture 5
Php web development
Introduction to JSP

What's hot (6)

KEY
Final Defense
DOCX
Unit 5 quesn b ans5
PPT
RomaFramework Tutorial Basics
ODP
Zen and the Art of Claroline Module Development
PPT
Graphics programming in Java
PDF
Deep C
Final Defense
Unit 5 quesn b ans5
RomaFramework Tutorial Basics
Zen and the Art of Claroline Module Development
Graphics programming in Java
Deep C
Ad

Viewers also liked (7)

PPT
Adentrándonos al Framework Symfony
PDF
Desarrollo rápido con PHP y Symfony (I): Introducción a Symfony
PDF
Symfony. La guia definitiva
PDF
Las buenas prácticas oficiales para aplicaciones Symfony
ODP
Desarrollo de aplicaciones web con PHP y symfony
PDF
deSymfony 2013 - Creando aplicaciones web desde otro ángulo con Symfony y A...
PPTX
Ejercicios de algoritmos
Adentrándonos al Framework Symfony
Desarrollo rápido con PHP y Symfony (I): Introducción a Symfony
Symfony. La guia definitiva
Las buenas prácticas oficiales para aplicaciones Symfony
Desarrollo de aplicaciones web con PHP y symfony
deSymfony 2013 - Creando aplicaciones web desde otro ángulo con Symfony y A...
Ejercicios de algoritmos
Ad

Similar to Symfony Components (20)

PPTX
Use Symfony2 components inside WordPress
KEY
Twig for Drupal @ Frontendunited Amsterdam 2012
ODP
Aspect-oriented programming in Perl
ODP
New Stuff In Php 5.3
ODP
Template Toolkit
PPT
PHP-03-Functions.ppt
PPT
PHP-03-Functions.ppt
PPTX
Templates, partials and layouts
PDF
Drupal 8 - Core and API Changes
PDF
Basic JavaScript Tutorial
PPT
FLossEd-BK Tequila Framework3.2.1
PDF
The Django Book chapter 4 templates (supplement)
DOCX
Process Synchronization Producer-Consumer ProblemThe purpos.docx
PDF
Java applet basics
PDF
6 introduction-php-mvc-cakephp-m6-views-slides
PDF
Winter%200405%20-%20Beginning%20PHP
PDF
Winter%200405%20-%20Beginning%20PHP
PPT
Flyr PHP micro-framework
PPT
Bb Tequila Coding Style (Draft)
PDF
Twig for Drupal 8 and PHP | Presented at OC Drupal
Use Symfony2 components inside WordPress
Twig for Drupal @ Frontendunited Amsterdam 2012
Aspect-oriented programming in Perl
New Stuff In Php 5.3
Template Toolkit
PHP-03-Functions.ppt
PHP-03-Functions.ppt
Templates, partials and layouts
Drupal 8 - Core and API Changes
Basic JavaScript Tutorial
FLossEd-BK Tequila Framework3.2.1
The Django Book chapter 4 templates (supplement)
Process Synchronization Producer-Consumer ProblemThe purpos.docx
Java applet basics
6 introduction-php-mvc-cakephp-m6-views-slides
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
Flyr PHP micro-framework
Bb Tequila Coding Style (Draft)
Twig for Drupal 8 and PHP | Presented at OC Drupal

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Electronic commerce courselecture one. Pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
Teaching material agriculture food technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Chapter 3 Spatial Domain Image Processing.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Empathic Computing: Creating Shared Understanding
Unlocking AI with Model Context Protocol (MCP)
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
MIND Revenue Release Quarter 2 2025 Press Release
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx
NewMind AI Weekly Chronicles - August'25-Week II
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Diabetes mellitus diagnosis method based random forest with bat algorithm
Electronic commerce courselecture one. Pdf
The AUB Centre for AI in Media Proposal.docx
Machine Learning_overview_presentation.pptx
Approach and Philosophy of On baking technology
MYSQL Presentation for SQL database connectivity
A comparative analysis of optical character recognition models for extracting...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Teaching material agriculture food technology
Dropbox Q2 2025 Financial Results & Investor Presentation
Chapter 3 Spatial Domain Image Processing.pdf

Symfony Components

  • 1. Open-Source PHP5 MVC Framework Agile Development VIEW PARTIALS, COMPONENTS, SLOTS and COMPONENT SLOTS PARTIALS SLOTS Reusable chunk of template code. A template can include partials whether A placeholder that you can put in any of the view elements (in the layout, it is in the same module, in another module, or in the global templates/ a template, or a partial). Filling this placeholder is just like setting a directory. Partials have access to the usual symfony helpers and template variable. The filling code is stored globally in the response, so you can shorcuts, but not to the variables defined in the action calling it, unless define it anywhere (in the layout, a template, or a partial). Slots are very passed explicitly as an argument. useful to define zones meant to display contextual content. Article Detail Best Articles Lastest Articles Template Layout Layout Slot Slot Article Partial Article Partial Article Partial Article Partial Article Partial Slot 1 + 1 Template = 1 Template Slot 2 Slot 2 Article Partial Article Partial Slot 2 USING A PARTIAL USING A SLOT Create a file named _<partial_name>.php, that contains the partial, in: To define a slot in a template: <myproject>/apps/<myapp>/modules/<mymodule>/templates/ Each template has the ability to define the contents of a slot. To include a partial: As slots are meant to hold HTML code, just write the slot code between a call to the slot(<slot_name>) and end_slot() helpers. <?php include_partial('<module>/<partial_name>’, array('<var>'=>$<var>)) ?> E.g.: Overriding the 'sidebar' slot content in a template Global partials: <?php slot('sidebar') ?> Should be in: <myproject>/apps/<myapp>/templates/ <!-- custom sidebar code for the current template--> <h1>User details</h1> To include a global partial: <p>name: <?php echo $user->getName() ?></p> <?php include_partial('global/<partial_name>’) ?> <p>email: <?php echo $user->getEmail() ?></p> <?php end_slot() ?> To include a slot: COMPONENTS <?php include_slot('<slot_name>’) ?> A partial with a logic behind. Template Is like an action, it can pass Headlines Sidebar To verify if a slot is defined: variables to a template <?php has_slot('<slot_name>’) ?> partial, except it's much faster. The logic is kept in a The has_slot() helper returns true if the slot has been defined before, Headlines Component Logic providing a fallback mechanism. components.class.php file in the actions/ directory, Headlines Partial Presentation E.g.: Including a 'sidebar' slot in the layout and the template is a regular partial. You can include components in components, <div id="sidebar"> or in the global layout, as in any regular template. <?php if (has_slot('sidebar')): ?> <?php include_slot('sidebar') ?> USING A COMPONENT <?php else: ?> <!-- default sidebar code --> Presentation: <h1>Contextual zone</h1> Create a file named _<component_name>.php, in: <p>This zone contains links and information relative to the <myproject>/apps/<myapp>/modules/<mymodule>/templates/ main content of the page.</p> ... <?php endif; ?> <?php foreach($news as $headline): ?> </div> <li> <?php echo $headline->getPublishedAt() ?> <?php echo link_to($headline->getTitle(),'news/show?id='.$headline->getId()) ?> </li> <?php endforeach ?> COMPONENT SLOTS ... A component which varies according to the module calling it. Component Logic: slots are named placeholders that you can declare in the view elements. Create a file named components.class.php, that is the class inheriting For a component slot, the code results from the execution of a component from sfComponents, in: and the name of this component comes from the view configuration. <myproject>/apps/<myapp>/modules/<mymodule>/actions/ Useful for breadcrumbs, contextual navigations and dynamic insertions. E.g.: <?php USING A COMPONENT SLOT class newsComponents extends sfComponents{ public function executeHeadline(){ To set a component slot placeholder: $c = new Criteria(); $c->addDescendingOrderByColumn(NewsPeer::PUBLISHED_AT); <?php include_component_slot('<component_slot_name>’) ?> $c->setLimit(5); $this->news = NewsPeer::doSelect($c); To define a default component slot in the view.yml (located in } <myapp>/config): } default: components: To call a component: <component_slot_name>: [<module_name>, <partial_name>] include_component('<module>', '<component_name>’, array('<var>'=>$<var>)) <?php include_component('news', 'headlines') ?> This will call the execute<partial_name> method of the <module_name>Components class in the components.class.php located Components accept additional parameters in the shape of an associative in <module_name> module, and will display the _<partial_name>.php array. The parameters are available to the partial under their name, and located in: in the component via the $this object: <myproject>/apps/<myapp>/modules/<module_name>/templates/ E.g.: call to the component: <?php include_component('news', 'headlines', array('foo' => 'bar')) ?> To disable a component slot in view.yml (located in <myapp>/config): in the component itself: all: <?php echo $this->foo; ?> // 'bar' components: in the _headlines.php partial: <component_slot_name>: [] <?php echo $foo; ?> // 'bar’ http://andreiabohner.wordpress.com This cheat-sheet is not an official part of the symfony documentation