Nelmioapidocbundle: How to change twig template for custom styling (proposal)

Created on 29 Oct 2014  路  14Comments  路  Source: nelmio/NelmioApiDocBundle

Hi,

Currently you cannot simply override the template that gets rendered by the HtmlFormatter. It is hardcoded to NelmioApiDocBundle::resources.html.twig. Since I cannot use the default symfony app/Resources/views/NelmioApiDocBundle solution, I need to change the template that gets rendered.

Can I make a PR, that adds a configuration option to override the resources template?

protected function render(array $collection)
    {
        return $this->engine->render('NelmioApiDocBundle::resources.html.twig', array_merge(
            array(
                'resources' => $collection,
            ),
            $this->getGlobalVars()
        ));
    }

Most helpful comment

@yonisolo for symfony 4 the exact path is :
templates->bundles->NelmioApiDocBundle->SwaggerUi->index.html.twig (with the "i" of "SwaggerUi" in lowercase)

All 14 comments

This would be useful for me as well.

Why couldn't you use the Symfony template override ?

@stof Because it would not be configurable then. I am creating a bundle that uses Nelmio and also needs to be overridable, if that makes sense.

Sorry, disregard, it works fine. I was simply using the wrong name.
The following works: app/Resources/NelmioApiDocBundle/views/method.html.twig (etc..)

Hello there,

I actually try to override template but it doesn't work.
I created app/Resources/NelmioApiDocBundle/views/layout.html.twig but it is not overriding the template.

Any ideas ? Thx a lot ;)

Well, there is no layout.html.twig in this bundle, so this explains why overwriting this template has no effect: the bundle does not use it.

Thx for your answer but it is a little bit weird. There is a layout.html in this bundle actually ^^

{% extends "NelmioApiDocBundle::layout.html.twig" %}

And this is the only file including assets (css, js, ...) and structure.

According to documentation I "just follow the convention: app/Resources/{BUNDLE_NAME}/views/{PATH/TO/TEMPLATE.html.twig}"; so I made
app/Resources/ApiDocBundle/views/Components/layout.html.twig but it didn't worked. So thanks to syzop (but not according to conventions)
I created app/Resources/NelmioApiDocBundle/views/layout.html.twig and it works for me.

Hi there,
I know this topic was originaly for Symfony3.x but in Symfony4, the standard overriding doesn't work,
under:
templates->bundles->NelmioApiDocBundle->Resources->views->SwaggerUI->index.html.twig
the overriding doesn't work at all...
Is there anybody to help for this please?

Edit: My fault, it works with: templates->bundles->NelmioApiDocBundle->SwaggerUI->index.html.twig

lets use template overwriting for that

@yonisolo for symfony 4 the exact path is :
templates->bundles->NelmioApiDocBundle->SwaggerUi->index.html.twig (with the "i" of "SwaggerUi" in lowercase)

@skhattane yes you're right thanks for pointing this typo error

I have a bundle and a project, and the project requires the bundle. How can I override this index.html.twig inside the bundle, not the project? Creating a folder templates/bundles.... on bundle root folder does not work.

please do not comment on closed issues, but rather open a new issue referencing this one, @bradesignstudio

we discussed in #1330 that it would be nice to have the possibility to extend the template instead of just replacing it. if somebody does a pull request for that, the bundle will get a configuration option to specify the template to use, and you could have your bundle contain the template and configure nelmio to use that template.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abidichrak picture abidichrak  路  5Comments

smuralidharan picture smuralidharan  路  3Comments

numediaweb picture numediaweb  路  4Comments

ajaypatelbardoli picture ajaypatelbardoli  路  6Comments

NicolasGuilloux picture NicolasGuilloux  路  4Comments