Shopware 6 - Not using custom theme - twig

Hello for some reason shopware is not using my custom theme.
I followed the official example and ended up with the following path:
E:\XAMPP\htdocs\sw\custom\plugins\MyPlugin\src\Resources\views\storefront\layout\header\logo.html.twig
Unfortanetely, when now tying to compile the theme using
theme:compile
plugin:update MyPlugin
cache:clear
There is no visible change on the website. I made sure that the Storefront and the Headless sales channel are using my theme. Trough:
theme:change
and the just went trough the dialogue two times.
The code inside the template is as follows:
{% sw_extends '#Storefront/storefront/layout/header/logo.html.twig' %}
{% block layout_header_logo_link %}
<h2>Hello world!</h2>
{% endblock %}
Any help is greatly appreciated!
Thank you very much in advance.

The problem was that the tool which autogenerates the plugin and theme dummy code, messes up the plugin name in the theme.json file, resulting in literally no behaviour.
Therefore, make sure that
"views": [
"#Storefront",
"#Plugins",
"#myPlugin"
],
is changed to
"views": [
"#Storefront",
"#Plugins",
"#MyPlugin"
],
Notice the change on the last line, make sure that the name matches your plugin name and then you are good to go.

Sometimes it is cache related so delete cache in settings or run command psh.phar cache in project root, u could also use command bin/console cache:clear

Related

How override a template?

Following the documentation to override catalog.html.twig, I see that the "Hello World!" display does not work.
I cleared the cache.
I also tried to override view.html.twig with the following logic:
file path :
/modules/foo/views/PrestaShop/Admin/Sell/Order/Cart/view.html.twig
the content :
{% extends 'PrestaShopBundle:Admin/Sell/Order/Cart:view.html.twig' %}
{% block cart_summary %}
Hello world!
{% endblock %}
But unfortunately nothing works.
Do you have any ideas ?
overriding the admin templates require installed module.
Simply create and install your module via 'module manager' in admin panel, then inside of the module create this path "views/PrestaShop/Admin/Sell/Order/Cart/view.html.twig".
It should work now.
You have to create a module, I think that I have to put the file inside the override folder, but no.
You have to create a module whit that tools of prestashop and the create the path in views like the other answer say.
The module can be generic and doesn't matter the hook.

How to test if Apostrophe is in "editor mode" in a twig template

I am wanting to apply conditional CSS and template code while my Apostrophe CMS installation in "editor mode." However I have not been able to find anything in the documentation.
I have attempted to use the data.global object and the data.page object with no luck.
I am hoping to use something like
{% if data.global.edit %}
<br>
<br>
{% endif %}
You can check for data.page._edit or data.piece._edit, depending on whether it's a page template or a show.html template for a piece, to see if a user has editing privileges. If you're using apostrophe-workflow and you want to see if the user is in draft mode (edit mode) vs live mode you can check data.workflowMode as well.

what exactly is haswidgets and widgets in bolt (or twig rather )?

I was just going through the Default theme of bolt CMS, and i came actoss the following lines of code:
{% if haswidgets('aside_top') %}
{{ widgets('aside_top') }}
{% else %}
I googled twig haswidgets and also twig widgets , but i could't find anything.
can somebody explain what these two methods are ? and what exactly do they do ?
They are a feature of Bolt. Extensions can push content to specific places in the backend and also to some places in the frontend, as long as the theme supports that. They are called widgets. the haswidgets() and widgets() twig functions are for checking and displaying them.
You can find more info here https://docs.bolt.cm/3.1/templating/widgets and here https://docs.bolt.cm/3.1/extensions/intermediate/widgets

Symfony Server crashes when extending FOSUserBundle's default template layout.html.twig

I am trying to get the basic user login running from the FOSUserBundle.
I am using Symfony 3.0.6.
I followed the description to setup everything from the FOSUserBundle:
https://symfony.com/doc/master/bundles/FOSUserBundle/index.html
DB is up and running everything seems fine except I cant figure out how to override the layout.html.twig from the FOSUserBundle.
I followed this description for achieving that:
https://symfony.com/doc/master/bundles/FOSUserBundle/overriding_templates.html
I now have a file "layout.html.twig" in the folder "Resources/FOSUserBundle/views" with the content being the same as in the last link provided above.
This leads to the following error:
Unable to find template "layout.html.twig" (looked into:
[somePathInfo]) in FOSUserBundle::layout.html.twig at line 1.
Now I changed the first line in the "layout.html.twig" Template to be
{% extends 'FOSUserBundle::layout.html.twig' %}
And this then leads to the symfony server to crash stating
>php bin/console server:run -v
[OK] Server running on http://127.0.0.1:8000
// Quit the server with CONTROL-C.
RUN "C:\xampp\php\php.exe" "-S" "127.0.0.1:8000" "[PATH]\myProject\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Resources\config\router_dev.php"
RES -1073741571 Command did not run successfully
[ERROR] Built-in server terminated unexpectedly.
I am stuck here...
Any ideas are very welcome.
EDIT: The FOSUserBundle installed by the composer (which I use through the current PHP-Storm plugin) is installed at the path:
[projectPath]\vendor\friendsofsymfony\user-bundle\Resources\views\layout.html.twig
In the docu however allways "FOSUserBundle" only is mentioned and I don't know how to figure out if that mapping fits to the path in my project.
Any hints for this issue are very wellcome as well.
When you override standart FOSUser layout you need to place your layout into app/Resources/FOSUserBundle/views/layout.html.twig. great, you did this. it's just a layout, it should not extend standart FOSUser layout, so remove line {% extends 'FOSUserBundle::layout.html.twig' %}. But usually developers make one base layout, in my case it is \app\Resources\views\base.html.twig, so if I want to override fosuser layout I will have in app/Resources/FOSUserBundle/views/layout.html.twig something like this
{% extends 'base.html.twig' %}
{% block title %}User Management{% endblock %}
{% block content %}
{% block fos_user_content %}{% endblock %}
{% endblock %}
In first line you extend your base layout not FOSUser. You may not extend something, maybe you have separate complete layout for this template.
The crash does make sense.
When you write:
{% extends 'FOSUserBundle::layout.html.twig' %}
The Symfony will first try to load app/Resources/FOSUserBundle/views/layout.html.twig. Failing to find the file will revert to similar path but inside the vendor directory. And if you are trying to extend FOS's template from within your FOS overriden template, that would create recursive loop:
app/Resource/FOSUserBundle/views/layout.html.twig
^^ extends
app/Resource/FOSUserBundle/views/layout.html.twig
^^ extends
app/Resource/FOSUserBundle/views/layout.html.twig
....
and so on...
So, this is not a way to solve the problem.
Make sure that your template is well placed in your app directory and not your bundle, as Denis Alimov suggested in a comment.

Yii 2 registerJs in twig templates

In the Yii 2.0 guide it says you can register Javascript code in a twig template like this:
{registerJs key='show' position='POS_LOAD'}
$("span.show").replaceWith('<div class="show">');
{/registerJs}
Tried this but it will simply output the whole snippet {registerJs ... as text on the page without adding it to the page's Javascript Code.
Similar commands like registerJsFile or registerCss aren't working either.
Am I missing something? Thanks!
EDIT:
As Mihai P. noted below, {registerJs} is syntax for Smarty templates. So, the question is: is there a similar way to register inline JS in Twig templates? The documentation only mentions registering assets.
You can use this in your Twig template, which is the current view, to call registerJs.
{% set script %}
var app = new Vue({
el: '#vue-widget',
data: {
message: 'Hello Vue!'
}
})
{% endset %}
{{ this.registerJs(script,4,'vue-widget') }}
The question is 3 years old, I put it here for someone runs into a similar problem.
You can use this in the Twig template with View constant like below:
{{ this.registerJs('$("span.show").replaceWith(\'<div class="show">\');', constant('\\yii\\web\\View::POS_HEAD')) }}
And, you can also call registerJs inside the Yii2 controller, which I think it makes the code cleaner
$this->getView()->registerJs('$("span.show").replaceWith(\'<div class="show">\');', \yii\web\View::POS_HEAD);
Your example is copied from the smarty section not the twig. There are some examples in the twig section that you might want to try.

Resources