Code snippets for symfony 1.x

Navigation

Including custom partials in admin generator pages

Here is a method i developed to include some custom partials at the end of the edit action of a module which adapts admin generator.

i just added this at the end of editSuccess.php file of my generator theme ($sf_data_dir/generator/sfPropelAdmin/<myCustomTheme>/templates/editSuccess.php)

[?php // include xtra partials ?]
<?php if ($this->getParameterValue('edit.partials')): ?>
<?php
$partials = $this->getParameterValue('edit.partials');
foreach( $partials as $partial => $vars ) : ?>
[?php include_partial('<?php echo $this->getModuleName() ?>/<?php echo $partial ?>', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?> <?php foreach ($vars as $var): ?> , '<?php echo $var ?>' => $<?php echo $var; endforeach; ?>)); ?]
<?php endforeach; ?>

then you just have to add the partials in the generator.yml like this :

edit:
  partials:
    partial1: [ var1a, var1b ]
    partial2: [ var2a, var2b ]

where var.. are the variables you want to include in each partial.

this can be easily made for list success also.

by Kostas Papadimitriou on 2007-01-08, tagged admin  custom  generator  include  partial  partials 

Comments on this snippet

gravatar icon
#1 Peter . on 2007-01-29 at 04:58

Hi Kostas, I'm gettign the following error: <quote> Parse error: parse error, unexpected $end in C:\wamp\php\PEAR\data\symfony\generator\sfPropelAdmin\default\template\templates\editSuccess.php on line 28 </quote> even if my generator.yml file doesn't have partials section. Any ideas?

gravatar icon
#2 robin van emden on 2007-03-05 at 11:10

Fast hack to make snippet work:

[?php // include xtra partials ?] <?php if ($this->getParameterValue('edit.partials')){ ?> <?php $partials = $this->getParameterValue('edit.partials'); foreach( $partials as $partial => $vars ) : ?> [?php include_partial('<?php echo $this->getModuleName() ?>/<?php echo $partial ?>', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?> <?php foreach ($vars as $var): ?> , '<?php echo $var ?>' => $<?php echo $var; endforeach; ?>)); ?] <?php endforeach; }?>