Skip to content

Commit

Permalink
Merge pull request symfony2admingenerator#514 from cedriclombardot/sh…
Browse files Browse the repository at this point in the history
…ow-sidebar

Enable to add a sidebar in show view
  • Loading branch information
cedriclombardot committed Jun 21, 2013
2 parents 9a184c4 + 6aaf337 commit 926d87a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
Expand Up @@ -4,6 +4,7 @@
{% use '../CommonAdmin/ShowTemplate/tabs.php.twig' %}
{% use '../CommonAdmin/ShowTemplate/show.php.twig' %}
{% use '../CommonAdmin/ShowTemplate/actions.php.twig' %}
{% use '../CommonAdmin/ShowTemplate/sidebar.php.twig' %}
{{ echo_extends( builder.getBaseAdminTemplate ) }}

{{ echo_block("stylesheets") }}
Expand All @@ -25,7 +26,16 @@
{{- block('title') -}}

<div class="row-fluid">
{{- block('show_tabs') }}
{{- block('show') -}}
{% if sidebar %}
<div class="span8">
{% endif %}
{{- block('show_tabs') }}
{{- block('show') -}}
{% if sidebar %}
</div>
<div class="span4">
{{- block('show_sidebar') -}}
</div>
{% endif %}
</div>
{{ echo_endblock() }}
20 changes: 20 additions & 0 deletions Resources/templates/CommonAdmin/ShowTemplate/sidebar.php.twig
@@ -0,0 +1,20 @@
{% block show_sidebar %}
{{ echo_block("show_sidebar") }}
{% for name, widget in sidebar %}
{% if widget.credentials is defined %}
{{ echo_if_granted(widget.credentials, builder.ModelClass) }}
{% endif %}
<div class="row-fluid">
<h2>{{ echo_trans(name,{}, i18n_catalog is defined ? i18n_catalog : "Admin" ) }}</h2>
{% if widget.partial %}
{{ echo_include(widget.partial) }}
{% elseif widget.render %}
{{ echo_render(widget.render is iterable ? widget.render.controller : widget.render, widget.render is iterable ? widget.render.params : {}) }}
{% endif %}
</div>
{% if widget.credentials is defined %}
{{ echo_endif () }}
{% endif %}
{% endfor %}
{{ echo_endblock() }}
{% endblock %}
28 changes: 28 additions & 0 deletions Tests/Twig/Extension/EchoExtensionTest.php 100755 → 100644
Expand Up @@ -413,6 +413,34 @@ public function testGetEchoTwigFilter()
$this->runTwigTests($tpls, $returns);
}

public function testGetEchoInclude()
{
$tpls = array(
'string' => '{{ echo_include( "::base.htmlm.twig" ) }}',
);

$returns = array(
'string' => array('{% include "::base.htmlm.twig" %}', 'include return a good include tag with string elements'),
);

$this->runTwigTests($tpls, $returns);
}

public function testGetEchoRender()
{
$tpls = array(
'controller' => '{{ echo_render( "MyController" ) }}',
'with_params' => '{{ echo_render( "MyController", {"hello": name } ) }}',
);

$returns = array(
'controller' => array('{% render(controller("MyController", { })) %}', 'controller return a good controller tag'),
'with_params' => array('{% render(controller("MyController", { hello: \'cedric\' })) %}', 'controller return a good controller tag'),
);

$this->runTwigTests($tpls, $returns);
}

protected function runTwigTests($tpls, $returns)
{
$twig = $this->getEnvironment(false, array(), $tpls);
Expand Down
14 changes: 14 additions & 0 deletions Twig/Extension/EchoExtension.php 100755 → 100644
Expand Up @@ -42,6 +42,8 @@ public function getFunctions()
'echo_trans' => new \Twig_Function_Method($this, 'getEchoTrans'),
'echo_twig_assoc' => new \Twig_Function_Method($this, 'getEchoTwigAssoc'),
'echo_twig_filter' => new \Twig_Function_Method($this, 'getEchoTwigFilter'),
'echo_include' => new \Twig_Function_Method($this, 'getEchoInclude'),
'echo_render' => new \Twig_Function_Method($this, 'getEchoRender'),
);
}

Expand Down Expand Up @@ -452,6 +454,18 @@ public function getEchoTwigAssoc(array $arr)
return '{ ' . implode(', ', $contents) . ' }';
}

public function getEchoInclude($twig)
{
return '{% include "'.$twig.'" %}';
}

public function getEchoRender($controller, array $params = array())
{
$params = $this->getEchoTwigAssoc($params);

return '{% render(controller("'.$controller.'", '.$params.')) %}';
}

/**
* Returns the name of the extension.
*
Expand Down

0 comments on commit 926d87a

Please sign in to comment.