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

What's hot

Final Defense
Final DefenseFinal Defense
Final Defense
Karthik Gomadam
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
Sowri Rajan
 
RomaFramework Tutorial Basics
RomaFramework Tutorial BasicsRomaFramework Tutorial Basics
RomaFramework Tutorial Basics
Luca Garulli
 
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module DevelopmentZen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Claroline
 
Graphics programming in Java
Graphics programming in JavaGraphics programming in Java
Graphics programming in Java
Tushar B Kute
 
Deep C
Deep CDeep C
Deep C
Olve Maudal
 

What's hot (6)

Final Defense
Final DefenseFinal Defense
Final Defense
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
 
RomaFramework Tutorial Basics
RomaFramework Tutorial BasicsRomaFramework Tutorial Basics
RomaFramework Tutorial Basics
 
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module DevelopmentZen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
 
Graphics programming in Java
Graphics programming in JavaGraphics programming in Java
Graphics programming in Java
 
Deep C
Deep CDeep C
Deep C
 

Viewers also liked

Adentrándonos al Framework Symfony
Adentrándonos al  Framework SymfonyAdentrándonos al  Framework Symfony
Adentrándonos al Framework Symfony
Rodrigo Miranda
 
Desarrollo rápido con PHP y Symfony (I): Introducción a Symfony
Desarrollo rápido con PHP y Symfony (I): Introducción a SymfonyDesarrollo rápido con PHP y Symfony (I): Introducción a Symfony
Desarrollo rápido con PHP y Symfony (I): Introducción a Symfony
David J. Brenes
 
Symfony. La guia definitiva
Symfony. La guia definitivaSymfony. La guia definitiva
Symfony. La guia definitiva
Nuuktal Consulting
 
Las buenas prácticas oficiales para aplicaciones Symfony
Las buenas prácticas oficiales para aplicaciones SymfonyLas buenas prácticas oficiales para aplicaciones Symfony
Las buenas prácticas oficiales para aplicaciones Symfony
symfony_bcn
 
Desarrollo de aplicaciones web con PHP y symfony
Desarrollo de aplicaciones web con PHP y symfonyDesarrollo de aplicaciones web con PHP y symfony
Desarrollo de aplicaciones web con PHP y symfony
Juan Eladio Sánchez Rosas
 
deSymfony 2013 - Creando aplicaciones web desde otro ángulo con Symfony y A...
deSymfony 2013 -  Creando aplicaciones web desde otro ángulo con Symfony y A...deSymfony 2013 -  Creando aplicaciones web desde otro ángulo con Symfony y A...
deSymfony 2013 - Creando aplicaciones web desde otro ángulo con Symfony y A...
Pablo Godel
 
Ejercicios de algoritmos
Ejercicios de algoritmosEjercicios de algoritmos
Ejercicios de algoritmos
jhonshebax
 

Viewers also liked (7)

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

Similar to Symfony Components

Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
Maurizio Pelizzone
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012
Rene Bakx
 
Aspect-oriented programming in Perl
Aspect-oriented programming in PerlAspect-oriented programming in Perl
Aspect-oriented programming in Perl
megakott
 
New Stuff In Php 5.3
New Stuff In Php 5.3New Stuff In Php 5.3
New Stuff In Php 5.3
Chris Chubb
 
Template Toolkit
Template ToolkitTemplate Toolkit
Template Toolkit
dwm042
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
Jamers2
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
ShishirKantSingh1
 
Templates, partials and layouts
Templates, partials and layoutsTemplates, partials and layouts
Templates, partials and layouts
Kadiv Vech
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
Shabir Ahmad
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme
 
FLossEd-BK Tequila Framework3.2.1
FLossEd-BK Tequila Framework3.2.1FLossEd-BK Tequila Framework3.2.1
FLossEd-BK Tequila Framework3.2.1
Siwawong Wuttipongprasert
 
The Django Book chapter 4 templates (supplement)
The Django Book chapter 4 templates (supplement)The Django Book chapter 4 templates (supplement)
The Django Book chapter 4 templates (supplement)
Vincent Chien
 
Process Synchronization Producer-Consumer ProblemThe purpos.docx
Process Synchronization Producer-Consumer ProblemThe purpos.docxProcess Synchronization Producer-Consumer ProblemThe purpos.docx
Process Synchronization Producer-Consumer ProblemThe purpos.docx
stilliegeorgiana
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
Sunil Pandey
 
6 introduction-php-mvc-cakephp-m6-views-slides
6 introduction-php-mvc-cakephp-m6-views-slides6 introduction-php-mvc-cakephp-m6-views-slides
6 introduction-php-mvc-cakephp-m6-views-slides
MasterCode.vn
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Flyr PHP micro-framework
Flyr PHP micro-frameworkFlyr PHP micro-framework
Flyr PHP micro-framework
Siro Díaz Palazón
 
Bb Tequila Coding Style (Draft)
Bb Tequila Coding Style (Draft)Bb Tequila Coding Style (Draft)
Bb Tequila Coding Style (Draft)
Siwawong Wuttipongprasert
 
Twig for Drupal 8 and PHP | Presented at OC Drupal
Twig for Drupal 8 and PHP | Presented at OC DrupalTwig for Drupal 8 and PHP | Presented at OC Drupal
Twig for Drupal 8 and PHP | Presented at OC Drupal
webbywe
 

Similar to Symfony Components (20)

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

Recently uploaded

AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 

Recently uploaded (20)

AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 

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