Permalink
Browse files

Merge pull request #28 from RapotOR/custom-templates

Allow to config custom templates
  • Loading branch information...
2 parents 7d0e562 + 5512c38 commit 3da80f2e0d0d77bc5bdc38302bedd425da6497a8 @Herzult committed Dec 18, 2011
@@ -10,8 +10,9 @@ class CategoryController extends Controller
public function listAction()
{
$categories = $this->get('herzult_forum.repository.category')->findAll();
-
- return $this->get('templating')->renderResponse('HerzultForumBundle:Category:list.html.'.$this->getRenderer(), array('categories' => $categories));
+
+ $template = sprintf('%s:list.html.%s', $this->container->getParameter('herzult_forum.templating.location.category'), $this->getRenderer());
+ return $this->get('templating')->renderResponse($template, array('categories' => $categories));
}
public function showAction($slug)
@@ -22,7 +23,7 @@ public function showAction($slug)
throw new NotFoundHttpException(sprintf('The category %s does not exist.', $slug));
}
- $template = sprintf('HerzultForumBundle:Category:show.%s.%s', $this->get('request')->getRequestFormat(), $this->getRenderer());
+ $template = sprintf('%s:show.%s.%s', $this->container->getParameter('herzult_forum.templating.location.category'), $this->get('request')->getRequestFormat(), $this->getRenderer());
return $this->get('templating')->renderResponse($template, array(
'category' => $category,
'page' => $this->get('request')->query->get('page', 1)
@@ -10,7 +10,8 @@ class ForumController extends Controller
{
public function indexAction()
{
- return $this->get('templating')->renderResponse('HerzultForumBundle:Forum:index.html.'.$this->getRenderer(), array(
+ $template = sprintf('%s:index.html.%s', $this->container->getParameter('herzult_forum.templating.location.forum'), $this->getRenderer());
+ return $this->get('templating')->renderResponse($template, array(
'page' => $this->get('request')->query->get('page', 1)
));
}
@@ -29,8 +30,9 @@ public function searchAction()
$results->setCurrentPage($page);
$results->setMaxPerPage($this->container->getParameter('herzult_forum.paginator.search_results_per_page'));
}
-
- return $this->get('templating')->renderResponse('HerzultForumBundle:Forum:search.html.'.$this->getRenderer(), array(
+
+ $template = sprintf('%s:search.html.%s', $this->container->getParameter('herzult_forum.templating.location.forum'), $this->getRenderer());
+ return $this->get('templating')->renderResponse($template, array(
'form' => $form->createView(),
'results' => $results,
'query' => $query
@@ -13,7 +13,9 @@ class PostController extends Controller
public function newAction(Topic $topic)
{
$form = $this->get('herzult_forum.form.post');
- return $this->get('templating')->renderResponse('HerzultForumBundle:Post:new.html.'.$this->getRenderer(), array(
+
+ $template = sprintf('%s:new.html.%s', $this->container->getParameter('herzult_forum.templating.location.post'), $this->getRenderer());
+ return $this->get('templating')->renderResponse($template, array(
'form' => $form->createView(),
'topic' => $topic,
));
@@ -27,6 +29,7 @@ public function createAction(Topic $topic)
$form->bindRequest($this->get('request'));
if (!$form->isValid()) {
+ $template = sprintf('%s:new.html.%s', $this->container->getParameter('herzult_forum.templating.location.post'), $this->getRenderer());
return $this->get('templating')->renderResponse('HerzultForumBundle:Post:new.html.'.$this->getRenderer(), array(
'form' => $form->createView(),
'topic' => $topic,
@@ -19,8 +19,9 @@ public function newAction(Category $category = null)
$topic->setCategory($category);
}
$form->setData($topic);
-
- return $this->get('templating')->renderResponse('HerzultForumBundle:Topic:new.html.'.$this->getRenderer(), array(
+
+ $template = sprintf('%s:new.html.%s', $this->container->getParameter('herzult_forum.templating.location.topic'), $this->getRenderer());
+ return $this->get('templating')->renderResponse($template, array(
'form' => $form->createView(),
'category' => $category
));
@@ -33,6 +34,7 @@ public function createAction(Category $category = null)
$topic = $form->getData();
if (!$form->isValid()) {
+ $template = sprintf('%s:new.html.%s', $this->container->getParameter('herzult_forum.templating.location.topic'), $this->getRenderer());
return $this->get('templating')->renderResponse('HerzultForumBundle:Topic:new.html.'.$this->getRenderer(), array(
'form' => $form->createView(),
'category' => $category
@@ -67,7 +69,7 @@ public function listAction(Category $category = null, array $pagerOptions)
$topics->setCurrentPage($pagerOptions['page']);
$topics->setMaxPerPage($this->container->getParameter('herzult_forum.paginator.topics_per_page'));
- $template = sprintf('HerzultForumBundle:Topic:list.%s.%s', $this->get('request')->getRequestFormat(), $this->getRenderer());
+ $template = sprintf('%s:list.%s.%s', $this->container->getParameter('herzult_forum.templating.location.topic'), $this->get('request')->getRequestFormat(), $this->getRenderer());
return $this->get('templating')->renderResponse($template, array(
'topics' => $topics,
'category' => $category,
@@ -89,7 +91,7 @@ public function showAction($categorySlug, $slug)
$posts = $this->get('herzult_forum.repository.post')->findRecentByTopic($topic, 30);
}
- $template = sprintf('HerzultForumBundle:Topic:show.%s.%s', $this->get('request')->getRequestFormat(), $this->getRenderer());
+ $template = sprintf('%s:show.%s.%s', $this->container->getParameter('herzult_forum.templating.location.topic'), $this->get('request')->getRequestFormat(), $this->getRenderer());
return $this->get('templating')->renderResponse($template, array(
'topic' => $topic,
'posts' => $posts
@@ -121,6 +121,15 @@ public function getConfigTreeBuilder()
->arrayNode('templating')
->addDefaultsIfNotSet()
->children()
+ ->arrayNode('location')
+ ->addDefaultsIfNotSet()
+ ->children()
+ ->scalarNode('category')->defaultValue('HerzultForumBundle:Category')->end()
+ ->scalarNode('forum')->defaultValue('HerzultForumBundle:Forum')->end()
+ ->scalarNode('post')->defaultValue('HerzultForumBundle:Post')->end()
+ ->scalarNode('topic')->defaultValue('HerzultForumBundle:Topic')->end()
+ ->end()
+ ->end()
->scalarNode('engine')
->defaultValue('twig')
->validate()
@@ -48,7 +48,13 @@ private function loadParameters(array $config, ContainerBuilder $container)
foreach ($config as $groupName => $group) {
if (is_array($group)) {
foreach ($group as $name => $value) {
- $container->setParameter(sprintf('herzult_forum.%s.%s', $groupName, $name), $value);
+ if (is_array($value)) {
+ foreach ($value as $subname => $subvalue) {
+ $container->setParameter(sprintf('herzult_forum.%s.%s.%s', $groupName, $name, $subname), $subvalue);
+ }
+ }else{
+ $container->setParameter(sprintf('herzult_forum.%s.%s', $groupName, $name), $value);
+ }
}
} else {
$container->setParameter(sprintf('herzult_forum.%s', $groupName), $group);

0 comments on commit 3da80f2

Please sign in to comment.