I am having issues using twig templates for email in SF2.
First, I created a template file located at:
MainBundle/Resources/views/Email/InviteNewUsers.twig
Next, I rendered the view as the body of my email: $this->get('mailer')->send($this->renderView('MainBundle:Email:InviteNewUsers.twig', array('code' => $invite->getCode())));
Unfortunately, this triggers an error: Unable to find template "MainBundle:Email:InviteNewUsers.twig"
is there something wrong with my file placement or my render command?
It was suggest that I might need a type in the template name, so I tested with InviteNewUsers.txt.twig and received the same error.
I believe the name of twig template needs to be InviteNewUsers.{_format}.twig. so it must be something like InviteNewUsers.html.twig, InviteNewUsers.xml.twig, or InviteNewUsers.text.twig etc
EDIT:
Also if your namespace includes first directory something like {Company}\BaseBundle\..., then your template path needs to be {Company}MainBundle:Email:InviteNewUsers.text.twig
Related
I have to say I am unclear on the real reason for the error, but my only observation is that this .css file is being treated as a Lua file for whatever reason, which is why we see the error below.
Module:Citation/CS1/styles.css
http://www.gwart.co.uk/Module:Citation/CS1/styles.css
Other related errors: http://www.gwart.co.uk/Les_Edwards
How can I either fix this issue or alternatively, if needed, make this be a file rather than a module
Probably the page is being parsed as Lua because the content model is "Scribunto". If the TemplateStyles extension is installed, an admin can apparently change the content model of the page from "Scribunto" to "sanitized-css" and the page will be parsed correctly.
Another approach if you are not an admin is to create a .css subpage in the Template namespace and then move it to the Module namespace. Creating it in the Template namespace automatically gives it the "sanitized-css" content model, and it keeps its content model when it is moved to the Module namespace.
There is a Phabricator ticket requesting that Module subpages ending in .css automatically have the "sanitized-css" content model, but I do not know what progress has been made on implementing that.
i got the job to edit a page. And now i can see the rendered and displayed page, but i canĀ“t find the template to work on it.
The controller which is rendering the page:
return $this->render('FEBundle:Public\Impressum:Impressum.html.twig',array());
So how do i get the path from a rendered file?
Probably in FEBundle/Resources/views/Public/Impressum/Impressum.html.twig
Starting from Symfony 2.7, you can use the Twig profiler: http://symfony.com/blog/new-in-symfony-2-7-twig-profiler
Referencing Templates in a Bundle
Referencing Templates in a Bundle - overriding-bundle-templates
templates should be in:
app/Resources/FEBundle/views/Public/Impressum/Impressum.html.twig
or in:
FEBundle/Resources/views/Public/Impressum/Impressum.html.twig
EDIT:
if you want server path from controller:
$parser = $this->container->get('templating.name_parser');
$locator = $this->container->get('templating.locator');
$path = $locator->locate($parser->parse('FEBundle:Public\Impressum:Impressum.html.twig'));
I have Meteor application that uses Iron-Router in which the rendered screen is dynamic based on the URL.
I have two parameters from the URL, station and screen.
In the routing code:
this.render(stationParam+screenParam, {to: 'content'});
However, I want to be able to check if the template stationParam+screenParam exists.
Is this possible?
All templates are stored as a field of a global object, Template. The question then is: How to check if this global object has a given field?
You have multiple ways to do it. My personal favourite using underscore:
if (_.has(Template, stationParam + screenParam)) { /* ... */ }
Underscore is included in Meteor. If you want to use it in a package, don't forget the api.use('underscore') in your describe callback.
See also: Determining if a javascript object has a given property
my script defines a absolute path in PHP and gives it to the twig template with the render()-function. All works well, I can access my variables with {{ varName }} in the view. But if I try to use a absolute path as a variable inside a include-command like {% include varName %} it will say: Unable to find template. This will even happen if the absolute path is correct.
What am I missing here?
Well it's weird but unfortunately I had no possibility to include a file from somewhere else not in the specific symfony structure. So I had to move all contents to the view folder.
I hope someone fixes this, which is anything but flexible.
To add template search paths to Twig_Loader_Filesystem, you can use
$loader->addPath($templateDir);
or
$loader->prependPath($templateDir);
Where $templateDir is a parent directory and $loader is the variable containing your Twig_Loader_Filesystem object. In your example, you would want $templateDir to be the path where the Bundle directory is located.
Then, in your include do something like this:
{% include 'Bundle\Somedir\somefile.html.twig' %}
Twig will then search all paths in looking for Bundle\Somedir\somefile.html.twig and will return the first one it finds.
The Twig documentation on this subject can be found here: http://twig.sensiolabs.org/doc/api.html#twig-loader-filesystem
Note: Choice of using addPath or prependPath depends on which order you'd like Twig to search the directories in. Paths added using prependPath will be searched before any of the previously loaded paths.
Caution: The search order applies to all templates so if the path/filename you use in the include statement is not unique, you could end up overriding another template.
i use display suite to style my taxonomy page and it suggests me some template files but i am not able to use that file, i put them in place but they do not include,
do you know how it will works please ? or any references ?!
this is my display suite screen
and i place file ds-reset--node-article-article-ds.tpl.php into address sites/all/modules/contrib/ds/layouts/ds_reset
but not thing gana happen
(would be a comment if I could :) You're supposed to put your template file in /sites/all/themes/your_theme/templates/, not in the DS folder.