adding namespaced twig paths - symfony

I would like to use bootstrap 4 CoreUi template in my symfony project.
I added it to my project with
composer require coreui/coreui
Now coreui is in my vendor directory, I would like to add a path in twig.yaml to simplify its access, according to the doc I modified my twig.yaml file like this :
twig:
# paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
paths:
- '%kernel.project_dir%/templates'
- '%kernel.project_dir%/vendor/coreui': coreui
I get an ErrorException :
Notice: Undefined index: value
The doc doesn't say much... so I don't know what to do at this point.

Apologies for posting the wrong link in my comments. The error you are getting is a twig "feature". Basicially just need to supply a value for the blank namespace.
twig:
#paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
paths:
#'%kernel.project_dir%/templates': '' # add : ''
'%kernel.project_dir%/vendor/coreui': coreui
Run bin/console debug:twig and all should be well.
Update: Based on the discussion below with #yceruto as well as this github issue, I changed the answer to simply comment out the default templates line. Turns out it is not needed and there is a pull request to remove it. Always wondered why it was there in the first place.

paths: is getting two parameters as array, here
%kernel.project_dir%/templates and %kernel.project_dir%/vendor/coreui are directories must be exists, if not exists you need to create or just remove if don't need one of.
Mine is like that:
twig:
paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'

Related

AsseticBundle Configuration - Explaination

there is no real detail in the documentation about the AsseticBundle Config - in config.yml.
assetic:
debug: "%kernel.debug%"
use_controller:
enabled: "%kernel.debug%"
profiler: false
read_from: "%kernel.root_dir%/../web"
write_to: "%assetic.read_from%"
java: /usr/bin/java
node: /usr/bin/node
ruby: /usr/bin/ruby
sass: /usr/bin/sass
# An key-value pair of any number of named elements
variables:
some_name: []
bundles:
# Defaults (all currently registered bundles):
- FrameworkBundle
- SecurityBundle
- TwigBundle
- MonologBundle
- SwiftmailerBundle
- DoctrineBundle
- AsseticBundle
- ...
assets:
# An array of named assets (e.g. some_asset, some_other_asset)
some_asset:
inputs: []
filters: []
options:
# A key-value array of options and values
some_option_name: []
filters:
# An array of named filters (e.g. some_filter, some_other_filter)
some_filter: []
workers:
# see https://github.com/symfony/AsseticBundle/pull/119
# Cache can also be busted via the framework.templating.assets_version
# setting - see the "framework" configuration section
cache_busting:
enabled: false
twig:
functions:
# An array of named functions (e.g. some_function, some_other_function)
some_function: []
I'm specially interested in
read_from: don't understand the path, too
write_to:
because I don't really understand how to use it.
So, I want to use SCSS and Compass and I have an folder in AppBundle/Resources/assets/styles/main.scss
What I have to setup in the config.yml, that assetic know how he find the main.scss as a global setting?
Unless you are trying to update the directory from which Assetic reads/writes (thus being /web by default), you don't need to change anything here. The configuration can be understood from a good part on the Symfony documentation. You'll find what you need in:
read_from: "%kernel.root_dir%/../web"
write_to: "%assetic.read_from%"
These are paths to a directory which is writable/readable, and exposed to the public. In this case, it means it will look for /path/to/app/../web for both readings and writings.
In a general manner, check for php app/console config:dump-reference X to find the default configuration of a given bundle, where X is the bundle config name. In your case, try the later: php app/console config:dump-reference assetic
Now, what you want is to use compass/sass from your view as far as I can see.
In your twig file, put the following:
{% stylesheets 'path/to/main.scss' filter='compass' %}
<link rel="stylesheet" type="text/css" href="{{ asset_url }}">
{% endstylesheets %}
After adding the configuration for compass if it needs to be tweaked, you should be all set.
Is it helping? it not, could you please provide more details?

Unrecognized option "resources" under "twig.form"

I didn't touch my project since a week and today I have this error when I want to go on my website
Unrecognized option "resources" under "twig.form"
I don't know why.. This was working very fine before...
Here is my config.yml :
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
globals:
breadcrumb_trail: "#apy_breadcrumb_trail"
form:
resources:
- 'AppBundle:Form:fields.html.twig'
If you have any idea.. :)
If you are on SF3 or higher, check that the yaml definition hasn't changed to specify a form template: the current one (3.0.*) should be like this:
twig:
form_themes:
- 'bootstrap_3_layout.html.twig'
source

Doctrine Mapping in Symfony2 using YAML

I have a question regarding YAML configuration of Doctrine in Symfony2.
I have created an entity via "doctrine:generate:entity", and chose YAML as the mapping format.
This didn't add any metadata on ../Entity/"MyEntity".php, which would allow me to update or create my schema.
As an example, if I run
./app/console doctrine:schema:create
it fails, saying:
[RuntimeException]
Bundle "MySuperBundle" does not contain any mapped entities.
My automapping is already set to "true".
If I choose to use annotation config this would not be a problem.
Did I miss something? Are there any extra steps that I should take?
Thank you in advance, regards,
Ivan
I just had a fun time looking at the Doctrine config initialisation code. What I found was:
Using auto_mapping results in various defaults being set for the single default entity manager; it leaves the type value as false
If type is false the config code looks into the default directory for likely config files, and as soon as it finds a file of a valid extension it decides that that's the way config is being done, in the order xml, yml, php
If it doesn't find any of those it assumes annotation
Do you have anything else at all in the Bundle/Resources/config/doctrine folder? If so, it might be throwing off the auto-detection.
That aside, basically if you've used defaults, and have some entity classes and valid config, what you're doing should be working without any additional config. You've said "auto_mapping" is true, but have you changed any other bit of Doctrine config?
It might be an idea to try configuring stuff explicitly, e.g. as described in the Symfony Doctrine docs, go from default config
doctrine:
dbal:
driver: "%database_driver%"
#etc
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
to explicit
doctrine:
dbal:
driver: "%database_driver%"
#etc
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: false
mappings:
MySuperBundleName:
type: yml
dir: Resources/config/doctrine

Change document Namespace from Bundle/Document to Bundle/Model

I'm using DoctrineMongoDBBundle, normally i put the documents into the MyBundle/Document directory and works fine but i want change to MyBundle/Model
after move my documents to new namespace i get a error message
[Exception]
You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles...
currently i'm using annotations for set the configuration, i dont want use xml or yml. this is the current config, how i can achieve this?
# app/config/config.yml
doctrine_mongodb:
connections:
default:
server: mongodb://localhost:27017
options: {}
default_database: "%database_name%"
document_managers:
default:
auto_mapping: true
Assuming your document is Acme/Model/Invoice.
You can adjust the mapping like this:
doctrine:
odm:
# ...
mappings:
Acme:
type: annotation
is_bundle: false
dir: %kernel.root_dir%/../src/Acme/Model
prefix: Acme\Model
alias: MyDocuments
Now use the the mapping like this:
$documentManager->getRepository('MyDocuments:Invoice');
If you want to keep the document inside a bundle ...
... just use the bundle's name i.e. AcmeDemoBundle instead of Acme as the mapping-name, set is_bundle to true and the dir option will be seen as relative to the bundle's root directory.
More information on the mapping options can be found in the documentation chapter DoctrineBundle Configuration#Mapping Information.
More information on how to store documents out of bundles can be found in this blog post.
The procedure is the same for Doctrine ORM btw.

How to enable Twig's dump() in Symfony2

Seeing various threads on this topic but not finding a working answer. Have a simple Symfony2 app (2.3.5) and trying to dump variables passed into my Twig templates. I have in my app/config/config.yml:
# Twig Configuration
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
and in my app/config/config_dev.yml:
services:
twig.extension.debug:
class: Twig_Extensions_Extension_Debug
tags:
- { name: twig.extension }
But using dump() in a twig still renders an empty page. I also increased memory limit in php.ini to 512 ... still nothing
Which part of this am I missing?
Try class: Twig_Extension_Debug instead. :)
In symfony2.3, this extension is automatically enabled when twig.debug is set to true, so you should be able to use the dump function.
Try {% debug var %} as shown in this link:
http://www.craftitonline.com/2011/06/symfony2-debugging-with-twig-extensions/
Because I didn't found the answer on the web, I will share my working solution here:
# app/config.yml
twig:
debug: %kernel.debug%
Then in a Twig template:
{% dump var %}
Tested on Symfony 2.7

Resources