Sylius: How to reference your own twig template in a grid? - symfony

This is not a duplicate of e.g. Referencing a template in Twig / Symfony2 because creating bundles as applications is deprecated/not recommended anymore and therefore the answer is not applicable anymore. How do I reference my own template in a Sylius grid?
What I tried:
1.
options:
template: "#App/Order/Grid/Field/channel.html.twig"
2.
options:
template: ":Order/Grid/Field:channel.html.twig"
3.
options:
template: "templates/Order/Grid/Field/channel.html.twig"
4.
options:
template: "Order/Grid/Field/channel.html.twig"
(I tried some of these on the basis of the documentation: https://docs.sylius.com/en/1.6/components_and_bundles/bundles/SyliusGridBundle/field_types.html#twig-twig , https://docs.sylius.com/en/1.6/components_and_bundles/bundles/SyliusGridBundle/your_first_grid.html)
In all cases it says the template was not found. Any ideas?

How do you create grid or customize them? For example, I am trying to customize Admin > Catalog > Options grid, so by this tutorial put these lines at the end of config/packages/_sylius.yaml file:
sylius_grid:
grids:
sylius_admin_product_option:
fields:
name:
type: twig
options:
template: "Grid/mytemplate.html.twig"
Secondly, I create folder "Order" in /templates, then "Grid" folder in "Order" dir, and then folder "Field" in "Grid" directory. There I create file "mytemplate.html.twig" with any content. Did you tried similar steps?

Related

how to customize the style of the form made from twig on Symfony?

hello I was wondering how to customize the form on symfony instead of having already a ready-made template (especially the bootstrap one).
Hello here is the solution to this problem :
To start, here is the place where you can change the theme of the forms to Symfony:
// project_name/config/packages/twig.yaml
twig :
...
form_themes: ['bootstrap_4_layout.html.twig']
if you want to see the default packages that are available you have to go to the following folder :
project_name/vendor/twig-bridge/Resources/views/Form
Now you can notice that twig file names match the style that you can add for your forms made with twig
so now if you really want to make your own style of form just create a twig file in that same folder 'project_name/vendor/twig-bridge/Resources/views/Form' and then replace that filename with 'bootstrap_4_layout.html.twig' in 'project_name/config/packages/twig.yaml'

EasyAdmin Using your Own Templates Problem

I am trying to override "new" template for EasyAdmin but system ignores template code.
Here is the relevant part of easy_admin.yaml
entities:
# List the entity class name you want to manage
Places:
class: App\Entity\Places
templates:
list: 'asdfasdf'
As you see, value of list attribute is invalid but system ignores it and works without error and i can not override the template.
Do you have a suggestion?
So, as I mentioned in the comment - for some reason easyadmin doesn't give any errors if specified template doesn't exists. So, you just need to place your new template in templates folder, in example, templates/admin/listPlaces.html.twig and then specify correct path in easyadmin's config file, in example:
entities:
Places:
class: App\Entity\Places
templates:
list: 'admin/listPlaces.html.twig'
If you use EasyAdmin 3.x, for that you can overwrite a specific template specifying it in your entity's Controller or you can create your own folder structures like symfony does.
In this example I am overwriting only the edit template for my 'studient' entity, if you want to change all the edits of your project you must do so by creating the folder structure as symfony does.
public function configureCrud(): Crud
{
return Crud::new()
->overrideTemplate('crud/edit', 'studient/edit.html.twig')
;
}
You can even combine both methods. Suppose that in addition to modifying only the template 'edit' of studient you want to modify the way in which easyadmin displays the flash messages for that you only have to create this structure in your templates folder: "templates\bundles\EasyAdminBundles\flash_messages.html.twig"
I leave the link with the documentation for EasyAdmin 3.x
overriding-templates

Custom theme's blueprints not being detected in Admin plugin at all

Following this example: https://learn.getgrav.org/forms/blueprints/example-page-blueprint
I created my video.yaml file under "user/themes/MYTHEMENAME/blueprints", contents of its file:
title: Gallery
'#extends':
type: default
context: blueprints://pages
form:
fields:
tabs:
type: tabs
active: 1
fields:
gallery:
type: tab
title: Gallery
fields:
header.txf:
type: text
label: Add a number
default: 5
validate:
required: true
type: int
header.sb:
type: select
label: Select one of the following
default: one
options:
one: One
two: Two
three: Three
Cleared all caches, but i still don't see that tab under "/admin/pages" or "/admin/pages/home" advanced tab. What's wrong? Is it bug?
UPDATED INFO
"user/themes/MYTHEMENAME/MYTHEMENAME.yaml":
enabled: true
dropdown:
enabled: true
"user/config/site.yaml":
title: domain.org
author:
name: Name
email: 'email#mail.com'
metadata:
description: 'analytical news feed'
generator:
Tried to put them under "user/blueprints/pages/" - still not EFFECT! Why such an easy tasks is too complicated in grav...
Your blueprint is correct, it works on my side.
You said you don't see that tab under "/admin/pages" or "/admin/pages/home". This is not how a blueprint works, blueprint is only available for its page template. You didn't mention any sample paths of your page so it seems your page use a different template.
If your blueprint is user/themes/yourtheme/blueprints/video.yaml, it is only available for the pages which use video template, for example user/pages/home/video.md. Your blueprint will not available to all pages on the site.
Similar to modular template, you need to put your blueprint in modular folder: user/themes/yourtheme/blueprints/modular/video.yaml, and your modular page needs to use that template as well user/pages/home/_myvideo/video.md

Sonata Admin overrides layout template per one Admin

I try to override layout template in Sonata Admin. I did all steps founded in official documentation, but my changes don`t work.
I did:
Copied from vendor appropriate template (standard_layout.html.twig) to app/Resources/SonataAdminBundle/views/. I will check if I override here template my changes applied to all of Admins in project (I want have this change only in one Admin)
In next step I created new file in my Bundle (Name/InfoBundle/Resources/views/JobOffer) and add there my custom template: findCandidate.html.twig. Below is content of this file:
https://gist.github.com/anonymous/5f4780a1ae8d7329cd91
Added to bundle service:
name_info.admin.offers:
class: Name\InfoBundle\Admin\JobOfferAdmin
tags:
- {name: sonata.admin, manager_type: orm, group: Info, label: Job offers}
arguments: [~, Name\Info\Entity\JobOffer, NameInfoBundle:JobOffer]
calls:
- [ setTemplate, [findCandidate, NameInfoBundle:JobOffer:findCandidate.html.twig]]
After that my changes are not applied. So probably I made mistake in services or maybe I have to call this template also in controller? I am not sure where I make mistake. Could anyone help me?
Probably you mistyped a template placeholder in setTemplate function.
Try to set it like:
calls:
- [setTemplate, [layout, NameInfoBundle:JobOffer:findCandidate.html.twig]]
It will change a standard_layout only for the selected admin.

Symfony KnpMenuBundle configuration across bundles

I'm using KnpMenuBudle in two different bundles of the same application. In one bundle I use also BraincraftedBootstrapBundle, so in my app/config/config.yml I put this specific config to style menus with bootstrap:
knp_menu:
twig:
template: "BraincraftedBootstrapBundle:Menu:menu.html.twig"
The problem is that configuration is set globally, so when i try to use KnpMenu in the bundle that doesn't require bootstrap I get an error.
How can I set this specific configuration for one bundle only?
I believe you can specify the template you want when you call the knp_menu_render twig method in your layout:
{{ knp_menu_render('main', {'template': 'BraincraftedBootstrapBundle:Menu:menu.html.twig'}, 'custom') }}

Resources