Website : Open source frameword based on Symfony 2.7
My entitie : Entity/Download.php (with properties "id", "creation_date" and "name")
I'm working on my own Bundle and I try to create a new datagrid based on my own entitie, I follow this tutorial. Below is what I've done :
Create /resources/config/datagrid.yml, with a very light datagrid.
Edit DependencyInjection/MyBundleExtension.php to load datagrid.yml.
Edit my twig view to render the datagrid :
{% import 'PimDataGridBundle::macros.html.twig' as dataGrid %}
{% block content %}
{{ dataGrid.renderGrid('custom_download', { localeCode: locale_code() }) }}
{% endblock %}
But this error is generated :
Twig_Error_Runtime: "An exception has been thrown during the rendering
of a template ("A configuration for "custom_download" datagrid was not
found.
-> If I try the same code with another gridname already existing that works then I believe the problem comes from my new datagrid but I don't understand what's wrong : does the kernel include my YML config file ? I don't think so.
Thanks for your help.
You create datagrid.yml in /resources/config folder.
But according OroPlatform conventions configuration file should be placed in Resources/config/oro folder of your bundle and named datagrids.yml.
Exactly in this path OroPlatform is looking for datagrid configuration.
https://github.com/oroinc/platform/blob/2.5/src/Oro/Bundle/DataGridBundle/Provider/ConfigurationProvider.php#L154-L160
Please move your configuration into correct directory and filename. And It will be work. And of course you should remove this file loading from DependencyInjection/MyBundleExtension.php OroPlatform do it automatically.
For more detailed understanding how you can use OroPlatform datagrid features please read bundle documentation
https://github.com/oroinc/platform/blob/2.5/src/Oro/Bundle/DataGridBundle/Resources/doc/backend/datagrid.md
Related
I'm a beginner in Symfony and I am trying to set up CKEditor for the Sonata News Bundle.
I have looked everywhere (even on German forums whereas I don't speak German !) but I cannot find any answer anywhere.
Does anyone have a clue or a solution to my question ?
Thank you everyone.
Louis
I would suggest you to use IvoryCKEditorBundle
Download the Bundle:
composer require egeloen/ckeditor-bundle
Register the Bundle, Then, update your app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
// ...
);
// ...
}
}
If you're using Symfony <= 2.8:
php app/console ckeditor:install
php app/console assets:install web
If you're using Symfony >= 3.0:
php bin/console ckeditor:install
php bin/console assets:install web
Then usage
The way I do it (symfony: 4.3.5, sonata: 3.54.1).
Download ckeditor JS lib and place it inside public/js so i.e. you should have the file:
your_app/public/js/ckeditor/ckeditor.js
and beside that file dirs: adapters, lang, plugins and skins and some js/css/md files.
Then override base sonata edit template with:
{% extends '#SonataAdmin/CRUD/base_edit.html.twig' %}
{% block javascripts %}
<script src="{{ asset('js/ckeditor/ckeditor.js') }}" type="text/javascript"></script>
{{ parent() }}
{% endblock %}
This code will include ckeditor to your pages and should be placed at: your_app/templates/edit.html.twig
Then, add to "templates" section edit:edit.html.twig so template you created would be used:
sonata_admin:
title: 'Your app Admin'
dashboard:
blocks:
- { type: sonata.admin.block.admin_list, position: left }
templates:
edit: edit.html.twig
This is file: your_app/config/packages/sonata_admin.yaml
Then, when you are adding new field from sonata admin bundle, inside configureFormFields your ckeditor fields should look like:
->add('field_name', null, array('attr'=> array('class' => 'ckeditor')))
Important part is adding array of attributes with class attribute.
Clear the cache and CKEditor should be working now.
I'm using symfony and in my bundle I need to create some translations, but I rather do it in a different domain than "messages", like FOS User Bundle does (they use the FOSUserBundle domain).
So I created a MyBundle.en.yml file with my translations, but they are not loaded. I've read in the documentation I need to do this:
$translator->addLoader('xlf', new XliffFileLoader());
$translator->addResource('xlf', 'messages.fr.xlf', 'fr_FR');
$translator->addResource('xlf', 'admin.fr.xlf', 'fr_FR', 'admin');
$translator->addResource(
'xlf',
'navigation.fr.xlf',
'fr_FR',
'navigation'
);
http://symfony.com/doc/current/components/translation.html#using-message-domains
But where should I do that?
Update
After some investigation, if I run the debug for the translations it says that all the translation I'm using for my domain in the template are missing.
My translation file is located at
src/Acme/Bundle/MyBundle/resources/translations/MyDomain.yml
I tried to located in app/Resources/translation/MyDomain.yml but same result.
I also tried to delete the cache (rm -rf app/cache) but still not working
Symfony will automatically do this for you if you place your files in the correct location(s). You can find a full description of the conventions assumed by Symfony in the documentation: https://symfony.com/doc/current/translation.html#translation-resource-file-names-and-locations
The Best Practices-guide recommends storing them in app/Resources/translations/. Alternatively you can put them in your bundle's translations folder: src/MyBundle/Resources/translations.
Please be aware that you have to specify your domain when using the translator, e.g. in your twig templates. See:
https://symfony.com/doc/current/components/translation.html#using-message-domains
https://symfony.com/doc/current/translation.html#twig-templates
you have to specify the domain name. for example in twig:
{{ some_things | trans({}, 'my_domaine_name') }}
If you have something like x.en.yaml and you want to use it inside a twing template you can do something like this:
{% trans from 'x' %}word_to_translate{% endtrans %}
I'm pretty new to Symfony development and i just tried to use the FOSUserBundle. I followed the guide Getting Started With FOSUserBundle on the official Symfony website.
Afterwards i wanted to test the functionality of the installation and visited the link www.linktomytestproject.dev/login which worked flawlessly. But when i tried to visit www.linktomytestproject.dev/register to test the registration functionality, i got the following errormessage:
Unable to find template "register_content.html.twig" (looked into: /home/vagrant/mytestproject/app/Resources/views, /home/vagrant/mytestproject/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form) in #FOSUser/Registration/register.html.twig at line 4.
500 Internal Server Error - Twig_Error_Loader
I checked the file register.html.twig, which contains the following code:
{% extends "#FOSUser/layout.html.twig" %}
{% block fos_user_content %}
{% include "register_content.html.twig" %}
{% endblock fos_user_content %}
When I change the third line into:
{% include "FOSUserBundle:Registration:register_content.html.twig" %}
The file is found correctly and i can use the registration functionality as intended.
But the change i made is inside the vendor folder, which obviously isn't affected by any means of version control. So i guess there has to be a place somewhere in the configuration files, where this file/foldermapping is affected.
I would really appreciate it, if someone could help me out with this question, even though this is probably a really basic problem.
First override the FOSUserBundle http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_controllers.html
After that, you can create view folders like in vendor and you can use views like that;
{% include "YourBundle:Registration:register_content.html.twig" %}
It's a bug a issue is open on github
Is a bundle issue, in my project I change on the file
\vendor\friendsofsymfony\user-bundle\Resources\views\Registration\register.html.twig
this
{% include "register_content.html.twig" %}
for this
{% include "#FOSUser/Registration/register_content.html.twig" %}
I have a Twig template in this folder structure
appName
app
resources
FosUserBundle
views
myTemplate.html.twig
views
Form
templateToRefer.html.twig
from -myTemplate.html.twig- I would like to reference -templateToRefer.html.twig- that is inside folder views that is brother of FosUserBundle folder. Is there any way to do it?
My way is this
{% form_theme form 'Form/fields.html.twig' %}
but I always get error
Unable to find template "Form/fields.html.twig" (looked into: /home/felpone/Scrivania/appName/app/Resources/views
you need to pass the full path 'AppBundle:Form:templateToRefer.html.twig'
The main layout file is src/BD/TestBundle/views/layout.html.twig.
I'm trying to extend it from a file located in src/BD/TestBundle/views/Default/index.html.twig.
{% 'BDTestBundle::layout.html.twig' } throws a unable to find the template error message.
Any ideas?
It should be {% extends 'TestBundle:Default:layout.html.twig' %}
TestBundle bundle name
Dedault directory name in Resources
layout:html:twig template name