Symfony template referencing - php

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'

Related

Shopware 6: How to Access Config Parameters in Twig Template of the Admin Module

I'm looking for a way to access configuration parameters in twig template of the admin module. I tried to access it by:
{{ shopware.config.pluginName.config.fieldName }}
The problem is that in the twig template of the admin module {{ shopware.config }} isn't available. I tried to access it by {{ dump(shopware.config) }} but it returns nothing.
Am I doing something wrong?
Is there alternative to access plugin's configuration parameters in the admin module?
Is there a way to pass php variables to twig template of the admin module?
Thanks in advance,
Cheers!
Try to use following service:
this.systemConfigApiService.getValues('domain', this.selectedSalesChannelId)
where domain is the Plugin name.
Of course, you should inject that service first
inject: ['systemConfigApiService']
Using that service you can provide config value to twig template.

Symfony / Orocrm : yml file is not set?

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

How to add a new domain for translations in Symfony

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 %}

symfony unable to find template

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

Symfony 2 multiple bundles, one template

I will have this structure:
-TaskBundle
-FrontendConroler
-BackendController
-Userbundle
-FrontendConroler
-BackendController
-HoursUserBundle
-FrontendConroller
-BackendController
This is right logic?
Second and main question, I will have 2 base templates, for Frontend and Backend, where I will push base template (one most logic place -BasetemplatesBundle?) ?
Yes, it is right structure. You can create CoreBundle, and store templates in it, or you can just create in app / Resources / views / frontend.html.twig, and backend.html.twig. Or with orther name.
You can call template:
{% extends '::frontend.html.twig' %}
{% extends '::backend.html.twig' %}
Creating and Using Templates

Categories