I'm trying to build Login form popup and I want to render LoginAction controller in twig.
I'm getting error like:
An exception has been thrown during the rendering of a template ("Template is not configured.").
My twig template:
{{ render(controller('SyliusUserBundle:Security:login'))}}
And in Security.yml
sylius_shop_login:
path: /login
methods: [GET]
defaults:
_controller: sylius.controller.security:loginAction
_sylius:
template: "#SyliusShop/login.html.twig"
logged_in_route: sylius_shop_account_dashboard
How to include template in twig controller render?
Edit:
Any other better approach to show login form in popup? My plan is to include custom_login.html.twig in Layout twig using render(controller('SyliusUserBundle:Security:login')). But not able to send specific twig templete to controller.
Related
So I'm writing a project using Symfony + Sylius. I have a form which gets submitted via ajax to a /{paymentId}/pay route, this in turn calls the payum controller which handles the payment and sends a redirect to /payment/capture/{token} which then redirects again to display a card details form, this card details form is loaded in an iFrame. However, the route for /payment/capture is served via http and therefore never appears in the iFrame due to this error:
Mixed Content: The page at 'https://www.example.com/checkout/complete' was loaded over HTTPS, but requested an insecure form action 'http://www.example.com/payment/capture/SOMETOKENVALUE'. This request has been blocked; the content must be served over HTTPS.
How can I force the payment/capture route to server https? I've tried a few things such as adding
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
to my templates and setting the scheme requirement in my order.yml:
sylius_shop_order_pay:
path: /{paymentId}/pay
methods: [GET]
defaults:
_controller: sylius.controller.payum:prepareCaptureAction
requirements:
_scheme: https
_sylius:
redirect:
route: sylius_shop_order_after_pay
sylius_shop_order_after_pay:
path: /after-pay
methods: [GET]
defaults:
_controller: sylius.controller.payum:afterCaptureAction
requirements:
_scheme: https
However since the actual /payment/capture route is generated at run time, I'm not sure if I can force it onto https.
I have also tried via access control:
access_control:
- { path: ^/payment, role: ROLE_NO_ACCESS, requires_channel: https}
Any help would be greatly appreciated. Thanks
EDIT:
complete.html.twig:
{{ form_start(form, {'action': path('sylius_shop_checkout_complete'), 'attr': {'class': 'ui loadable form final-step', 'novalidate': 'novalidate', 'target' : 'card-details'}}) }}
{{ form_errors(form) }}
<input type="hidden" name="_method" value="PUT" />
{% include 'SyliusShopBundle:Common/Order:_summary.html.twig' with {'edit': true} %}
{{ form_row(form._token) }}
{{ form_end(form, {'render_rest': false}) }}
<iframe width="100%" height="670px" name="card-details" style="border: none;"></iframe>
checkout.js:
let form = jQuery("form[name='sylius_checkout_complete']");
if (form.length) {
form.submit()
}
I have a problem with generating relative URL in symfony 2.7 project
My project is hosted behind a proxy that redirect URL to the target VM, like this - example.com/oblounge/bo/ to vmhostname/
All my URL are generated in relative
Here is my problem
For example when I'm on this page
http://example.com/oblounge/bo/admin/articles/actualite?section=127
All generated likns are malformated, the "/admin/articles" is duplicated
http://example.com/oblounge/bo/admin/articles/admin/articles/actualite?section=127
Note: The problem is occurred only for rendered controllers
The render action
{{ render(controller('AppBundle:Back/Article/Article:sectionsArticle', { 'rubric': 'actualite' })) }}
The rendered twig
{% for section in sections %}
<li><i class="fa fa-circle-o"></i>{{ section.name }}</li>
{% endfor %}
My routing.yml
app:
resource: "#AppBundle/Controller/"
type: annotation
The prefix of my admin controller
/**
* #Route("/admin")
*/
class ArticleController extends BaseArticleController
{
I would suggest you give a look at your routing.yml file that is referenced within your bundle.
If you've already defined a prefix for the route in the routing.yml of you app/config there is no need to repeat it in the routing of your bundle , otherwise there will be a duplication of prefixes as in your case.
Example:
This is the routing.yml in the App\config folder
tutoLexikTestBundle_parents:
resource: "#tutoLexikTestBundle/Resources/config/routing/parents.yml"
prefix: /parents
And this is the one of the bundle
parents_show:
path: /{id}/show
defaults: { _controller: "tutoLexikTestBundle:Parents:show" }
I don't need to repeat the prefix 'Parents' in the path
I'm using Symfony , I wanna redirect the user to a specific frame in a page
So How can i translate this <a href="index.html#about"/> to twig ? I tried <a href="{{path('pl_index')}}#about"/> but it doesnt work
in twig you can use {{path('_welcome') }} and it will send you to your home index, check your route.yml and you can see what are the paths generated by symfony.
for example this is my config.yml:
//savabundle config.yml
sava_inventario_construccion:
path: /productos/construccion
defaults: { _controller: savaInventarioBundle:Inventario:construccion }
sava_inventario_index:
path: /productos/
defaults: { _controller: savaInventarioBundle:Inventario:index }
if i want to generate www.mypage.com/productos/construccion#about link, this is what my html should look like
<a href="{{path('sava_inventario_construccion') }}#about"/>
you can read more in here
http://symfony.com/doc/current/book/templating.html
I try to retrieve the global param that i define in parameters.yml and config.yml
in FOSUserBundle.en.yml under registration, in message i try to pass %myparam% and in my email.txt i try pass %myparam%:param like this
{{ 'registration.email.message'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl,'%myparam%':myparam}, 'FOSUserBundle') }}
but it dosen't works.
and can i insert html inside yml and new line?
thanks
In your config.yml under fosuserbundle configuration.
confirmation:
enabled: true
template: MYMailBundle:Registration:email.html.twig
By doing this you are creating a twig template where you can render your variables and format your html how you want.
If you want to create a newline in your yml file I think you could do it by adding a \n.
How can I detect in which bundle am I?
for exemple, when I'm in web.com/participants/list, I want to read "participants".
In order to get the bundle name in the controller:
// Display "AcmeHelloBundle"
echo $this->getRequest()->attributes->get('_template')->get('bundle');
And inside a Twig template:
{{ app.request.get('_template').get('bundle') }}
In order to get the controller name in the controller:
// Display "Default"
echo $this->getRequest()->attributes->get('_template')->get('controller');
And inside a Twig template:
{{ app.request.get('_template').get('controller') }}
In order to get the action name in the controller:
// Displays "index"
echo $this->getRequest()->attributes->get('_template')->get('name');
And inside a Twig template:
{{ app.request.get('_template').get('name') }}
AFAIK it's not yet possible (at least in a easy way). You should use reflection. I wrote a quick and dirty service to do get bundle name ang guess entity/repository/form names based on my conventions. Can be buggy, take a look at: http://pastebin.com/BzeXAduH
It works only when you pass a class that inherits from Controller (Symfony2). Usage:
entity_management_guesser:
class: Acme\HelloBundle\Service\EntityManagementGuesser
In your controller:
$guesser = $this->get('entity_management_guesser')->inizialize($this);
$bundleName = $guesser->getBundleName(); // Acme/HelloBundle
$bundleShort = $guesser->getBundleShortName(); // AcmeHelloBundle
Another possibility would be using kernel to get all bundles: Get a bundle name from an entity
Well you can get the controller of the current route by,
$request->attributes->get('_controller');
You can parse the bundle name from it.
You can get the bundle name in the controller simply like that:
// Display "SybioCoreBundle"
echo $this->getRequest()->attributes->get('_template')->get('bundle');
And inside a Twig template:
{{ app.request.get('_template').get('bundle') }}