Sonata Block Bundle SimpleBlock rendering - symfony

I'm using SonataBlockBundle in my current project.
I create a SimpleBlock and render it in my twig template with something like
{{ sonata_block_render('name' : 'myBlock') }}.
But the block consists of title and body, is there a way to render title and body separately, like I can do with form fields?
Thank you in anticipation!

The best way to go there would be to create a custom BlockService (see http://sonata-project.org/bundles/block/master/doc/reference/your_first_block.html for instructions about that), with a custom twig template where you will be able to specify your title/body rendering.

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'

Drupal 8 Twig Page Fields

So I'm just getting started with Drupal and Drupal 8 and have a hard time understanding accessing twig content. Ideally what I would like to do is require some fields using the structured content.
When a type of structured content is used I would like to load a specific twig template and access the fields by machine readable name. This will allow me to setup template types with specific requirements for content.
I'm struggling with 2 parts and maybe what I want to do isn't possible in drupal. The first part how do I assign a page template based on structured content type?
The second issue is how do print out specific fields. I'm able to print all fields using {{page.content}} but {{page.content.field_name}} prints nothing. I'm very confused how to proceed forward. I know I can use modules and assign them to sections but for structured data types this won't allow for rigid enforcement of data collection like structured content. Some of this content flows outside a single content area so I'd really like to do it in a main layout file.
Thoughts?
For defining page template based on content type:
You can have:
page--front.html.twig - For front page
page--user.html.twig - For user page
page--youtube_videos.html.twig - For content type (here it is: youtube_videos)
For print content fields, you need to goto node.html.twig
For image field: {{ content.field_image }}
For title: {{ label }}
Tag field: {{ content.field_tags }}

Output image field in Twig and D8

I created a basic page with a NID of 176. My basic page content type contains a field called field_banner_image.
In my templates directory I created a file called page--node--176.html.twig and the template works.
I saw a few threads where you can access the node content via {{ content.field_name }}, however, my content appears to NULL every time.
I managed to output the URL of my image field via:
{{ file_url(node.field_banner_image.entity.uri.value) }}
I feel like there has to be an easier/better way of doing this. Any suggestions? Why is content null in my twig templates?
If your template is named page--node--176.html.twig, it is actually a page template overriding the base page template page.html.twig, so you will have access to all page variables but not those in your node.
Although your node type is called "page", it is still a node, and the template for it would be node--176.html.twig which overrides node.html.twig.
In your node--***.html.twig you will have access to the content variable. Let me know if you need help.

fosuserbundle override template css

I'm trying to override the FOSUserBundle Templates as show here:
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.md
I used the second method, I created my own bundle and put the templates in
myBundle/Resources/Views/Security/login.html.twig
and
myBundle/Resources/Views/Registration/register.html.twig.
both templates start with:
{% extends "::nologbase.html.twig" %}
where nologbase.html.twig is defined in app/Resourcer/views.
well, the first one (login) is correctly displayed but the second one (register) shows row html with no css.
I cleared the cache and I also tried to display only the extended template and compared the source code. it is exactly the same!
any idea?
thanks

How to create reusable control in Symfony2?

How can I create a reusable panel based on http://getbootstrap.com/components/#panels-heading in Symfony 2 and Twig? I mean how to create resusable control that I can embed in my twig page and provide to it header text and body, which will contain html and some other twig components (e.g. form controls).
This control should contain all the HTML that come from bootstrap panel example and I will only provide header text and body ... and control put this in appropriate place.
http://twig.sensiolabs.org/doc/tags/extends.html
Are you talking about extending templates? That way you can reuse all the HTML that came from bootstrap and just overwrite the sections you need.
In Symfony2 the extends syntax is something like:
somefile.twig.html
{% extends 'AcmeSomeBundle:Default:bootstrap.template.html.twig' %}
Look at the documentation link above for more details.

Resources