Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use members templates inside my views? #52

Closed
ppi-buck opened this issue Jun 11, 2018 · 9 comments
Closed

Use members templates inside my views? #52

ppi-buck opened this issue Jun 11, 2018 · 9 comments

Comments

@ppi-buck
Copy link

Q A
Bug report? no
Feature request? no
BC Break report? no
RFC? yes

Hey again,

I'm not really that experienced with using twig but I got my site working on twig now because I want to include the templates you provide inside my views like so:

{% extends 'Fred/layout.html.twig' %}

{% block content %}
    {{ include('MembersBundle::Registration/register.html.twig') }}
{% endblock %}

It always throws an error Variable "form" does not exist. Is my approach totally wrong? Or am I missing something?
My goal is to use the register form/login form etc inside my custom styling.

Thanks in advance

@aarongerig
Copy link
Contributor

Hi @ppi-buck
It's actually quite simple. Have a look at this, it explains how to override a template of a third-party bundle. https://symfony.com/doc/3.3/templating/overriding.html

Hope this helps!

@ppi-buck
Copy link
Author

ppi-buck commented Jul 4, 2018

Hey Aaron,

thanks for your response! I actually managed to replace templates just the way you described. What I'm struggling with though is how to use this extension properly inside my project.

Right now I'm doing it this way which to me seems kinda 'hacky'...

In my Controller I defined some new actions for the different functions of the MembersBundle I need.

    public function loginAction(Request $request) {
        $response = $this->forward('MembersBundle:Auth:login');
        $this->view->output = $response->getContent();
    }

    public function registerAction(Request $request) {
        $response = $this->forward('MembersBundle:Registration:register');
        $this->view->output = $response->getContent();
    }

I then return the result to my views and render those out. Doesn't seem right to me since the $response also contains the HTML head and everything. Also when I e.g. register a new user via the registerAction and the corresponding view it redirects to the default view of the members bundle rather than keeping me inside my views...

So if you or anyone else can hint me into the right direction I would really appreciate.
Maybe I could even provide a PR than that explains how to use this extension for other developers like me that are not as experienced with Symfony (yet).

Cheers and have a good day!

@solverat
Copy link
Member

closed doe inactivity.

@jantomicky
Copy link

jantomicky commented Sep 25, 2020

@ppi-buck have you found a solution? I am facing the same issue. Specifically, I need to:

  1. Display the login form in my own AppBundle template / layout, in a modal window.
  2. Extend the MembersUser Class Definition / DataObject(s) and reflect the new fields in the user profile settings form.

But I am lost as to how, @solverat? Overriding the templates as mentioned above does not work, as MembersBundle uses its own controllers, and is completely separated from my AppBundle, so I can't "just" override the template and then do this:

{% extends '@AppBundle/layout.html.twig' %}

As there will be missing view variables. I've read up on overriding bundle parts, and tried to decorate MembersBundle\Controller\AuthController, but all I got was this exception:

ServiceNotFoundException
You have requested a non-existent service "MembersBundle\Controller\AuthController".

The above mentioned solution of forwarding the requests also seems a bit weird. So, what is the correct, recommended workflow here?
Decorating? Overriding the MembersBundle controllers completely, "copy-pasting" the actions, making my own form definitions and custom routes?

This is probably just me lacking Symfony knowledge, but it would be nice to provide example(s) on how to actually integrate MembersBundle into another project views.

@solverat
Copy link
Member

solverat commented Nov 2, 2020

I'm afraid, but I think you need to invest more time in learning symfony / pimcore principals.

Just by adding a folder structure like in the screenshot below, you're able to override every single members template (and extend them of course from your app layout).

image

Overriding controllers should be the final task and is not recommended. Just use one of the plenty events, members comes with: https://github.com/dachcom-digital/pimcore-members/blob/master/docs/40_Events.md.

@solverat
Copy link
Member

solverat commented Nov 2, 2020

Extend forms: Also symfony standard: https://symfony.com/doc/4.4/form/create_form_type_extension.html

@jantomicky
Copy link

jantomicky commented Nov 4, 2020

@solverat Thank you for responding, and for the links. Oh, no doubt about that, there is still much for me to learn with Symfony & Pimcore.

I am not sure we understand each other though; I do understand how bundle templates overriding works, however when I did what you suggest, created the folder structure as you show here, and extended my app layout, it didn't work. That's because I use my own BaseController where set up many view variables common to all my documents. These are then not available, as the "request processing" still works via "your" (MembersBundle) controllers which – of course – don't extend my BaseController and therefore I get "missing variable" Twig errors.

Either way, in the end I solved it by overriding the controllers with my own AppBundle controllers as I couldn't find any other way of doing this.

Still, thank you very much for taking the time to respond!

@aarongerig
Copy link
Contributor

@jantomicky Then maybe Twig globals might be something for you: https://symfony.com/doc/4.4/templating/global_variables.html

@jantomicky
Copy link

Thank you @aarongerig, I'll take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants