TPL email template in Symfony2 - php

I used a very simple template (.tpl) for receive emails in my php application. Some similar this:
Date : {date}
Name : {name}
Mail : {email}
Subject : {subject}
{message}
Now, I have migrated this app to Symfony, ¿how can I used this template?
If I do:
$this->renderView('MyBundle:Template:support.tpl', $params), 'text/html');
This not work in Symfony2.
Any Idea??
Thanks!

Symfony doesn't know .tpl files and your syntax. Simply use twig!
Date : {{ date }}
Name : {{ name }}
Mail : {{ email }}
Subject : {{ subject }}
{{ message }}
Of course your file have to end to .twig
$this->renderView('MyBundle:Template:support.txt.twig', $params);

Related

Laravel translate markdown mail template

'How can I translate the markdown email template ?
I tried to use __() inside the template but it doesnt work.
My template :
<x-mail::message>
# Password
__{{'Your password is'}} : {{ $password }} // it is displaying without being translated
</x-mail::message>
Try using the #lang directive and publish your language files using php artisan lang:publish.
#lang('Your password is') : {{ $password }}

Laravel localization of the markdown mail

I am trying to use localization in the Laravel markdown mail template, followed the manual but emails are not being translated when I receive it.
Calling the mail method:
Mail::to($email)->locale('no')->queue(new UserRegistered($data));
and my markup email template is:
#component('mail::message')
{{ __('A new user registration request has been received.') }} // it is displaying without being translated
{{ __('Test String') }} // it is displaying without being translated
{{ trans('Test String') }} // it is displaying without being translated
#lang('Test String') // it is displaying without being translated
#endcomponent
I have my en.json and no.json files in lang directory
{
"Test String": "Teststreng"
}

Find Symfony Widget Content File Location

For the first time, i am working on Symfony widgets.
{% render "EducateToolsBundle:Shared:selectMenu" with {'entity': 'Stores'} %}
its Meaning is SharedController -->selectMenuAction
{% form_theme form 'EducateToolsBundle:shared:_form_theme.html.twig' %}
What is the meaning of this.
From where i am getting the values to this form .?
You must look at selectMenuAction() method in the Shared controller. It is that function that set what template is used. if using the default Symfony coding standards it should be something like selectMenu.html.twig in a Shared sub folder in the Resources/views of the bundle.
You should looks at the documentation first :
https://symfony.com/doc/current/form/form_customization.html
Because we won't teach you symfony here, it's very well explain in the documentation and it is a task too big for us.
In your case theForm.id is the field of the formType we want to displays.
If we want to display the <input> of an form of user lastname we would use
form_widget(userForm.lastname)
form_widget tells symfony to display only the widget (the ) of the id given.
if you want to have a label + input + the errors of the field you could use
form_row(userForm.lastname)
wich is almost equal to
<div>
{{ form_label(form.lastname) }}
{{ form_errors(form.lastname) }}
{{ form_widget(form.lastname) }}
</div>
(it depends of the form theme, but you should read the doc for the details ;) )

Parse a variable content in TWIG

I have an given template file with following content:
Welcome, {{ user }}
In my PHP File I load this content by:
$welcome = file_get_contents(APPPATH . 'classes/Plugins/Core/testplugin/view/frontend/index.html');
So that's in template:
"Welcome, {{ user }}"
Now, if I give this content into my template:
$twig->welcome = $welcome;
$twig->user = "Tom";
Template output (html):
{{ welcome }}
Template output (browser):
Welcome, {{ user }}
My problem: Template engine won't replace my user given in twig string!
Any ideas? I tried using following filters:
{{ welcome|nl2br|raw }}
So you have a string in your template which in itself is a template. Then you need to tell Twig to treat your template variable as a template, otherwise it'll just treat it as string. For this there's the template_from_string function.

List files in Dir using Pyro

I want to list all files in a directory Using PyroCMS.
Using the Files module each client has their own folder, the folder is their User ID
\files\clients\{ID}\
I need something like this.
{{ foreach file in { files:/clients/{{ user:id }} } }}
{{files:current_file_name}}
{{ endif }}
You should be able to do something like this...
{{ files:listing folder="/files/clients/{{ client_id }}" }}
Download {{ name }}
{{ /files:listing }}
You will need to set the client_id variable though. You could set it in your contoller and use:
$this->template
->set('client_id', $client_id)
->build('page-template-goes-here');
Or even use the current user with the tag:
{{ user:id }}
I haven't tested this, but you should be able to get something going.
From here:
http://docs.pyrocms.com/2.1/manual/index.php/modules-and-tags/tag-reference/files
http://docs.pyrocms.com/2.1/manual/index.php/modules-and-tags/tag-reference/user

Categories