hi guys, After run `docker/sdk console twig:cache:...
# help
a
hi guys, After run
docker/sdk console twig:cache:warmer
. It raise error
Template "@HomePage/views/home/home.twig" is not defined.
Any suggest for this issue ?
p
Heyhey, have you looked for that string in your whole project?
@HomePage/views/home/home.twig
or just
home.twig
a
in .patchCache: @HomePage/views/home/home.twig => false
We have created a green theme for the DE store that inherits from the default theme
p
But then it sounds pretty clear to me… It seems to look for a
src/Pyz/Yves/HomePage/Theme/<your-theme-name>/views/home/home.twig
file. Do you have that file?
a
I can't find that file, because I think it applies the inheritance rule that will take the parent theme's file as default
p
“I can’t find that file” but that seems to be the problem. you should have
src/Pyz/Yves/HomePage/Theme/default/views/home/home.twig
. just copy it over to your theme folder
a
I have checked that this file already exists. In case I copy with green theme
src/Pyz/Yves/HomePage/Theme/green/views/home/home.twig
. It no longer gives error home.twig file but it gives error another twig file in another page
p
@mammoth-ram-1172 Do you have more tips about proper theming without copy&pasting all the individual files?
a
I just followed the course, but it doesn't work well on green theme on DE store but works fine on AT default theme store
I can see that all pages in Pyz have a default theme folder, but no green folder. When I manually copy from default theme page by page it works fine. Do I need to do it manually, because I think it should be inherited when there is no such file, it will be in default
Do you have any tutorials without copy paste?
m
When you create a theme, you just override what you need. You don’t have to copy and paste everything as Spryker will get it from the parent folder. The green folder is the one we created as a theme for creating a new theme. Spryker comes just with a default theme. I checked my Homepage/default and the home.twig is present. If it works for AT, it should work also for DE
a
• The problem is after I clear the cache "cache:empty-all". And then run homepage on store DE(green theme) first. An error will be generated • In the following case I clear the cache "cache:empty-all". And then run homepage on store AT(theme default) first. Works well for both stores
m
could you please share the steps you followed, or at what step in the course, so I can simulate this issue? also the themes’ array definition
a
Step 1. Create new theme "green" - Copy all code in src/Pyz/Yves/ShopUi/Theme/default/ - Change background theme green - Config new theme in config/Yves/frontend-build-config.json Step 2. Create theme green for store DE - Create file src/Pyz/Shared/TwigDE/TwigConfig.php( you can see code in record) Step 3. Clear cache and prefill cache - docker/sdk console cache:empty-all - docker/sdk console twigcachewarmer - Go to Store DE and check -> You can found error Step 4. Clear cache - docker/sdk console cache:empty-all - Go to Store AT and check -> Works well for both stores Link record: https://www.loom.com/share/12b3a2a512df4e5b9c973c4bef428eae?sid=061699ab-60d7-442f-b154-b0a3e2e13b5f
@mammoth-ram-1172 Is something wrong?
m
I’m going to give it a try and let you know.
Ok, found it! So , in TwigConfig, for TwigDE, just override getYvesThemeName() to return green. The getThemeDefault() has to keep pointing to default, otherwise the cachewarmer won’t read from default folders. The explanation is in the
Twig Cache
lesson of the course. Which shop type and version are you using?
a
It works fine for me, but when testing a ProductDetailpageDE it doesn't work according to the store. When I clear the cache • Go to the DE store. DE is ok, But then continue to go to AT store. The problem happened. AT store it reuses view of pdp.twig of DE store. • Same for the reverse case. Go to the AT store. AT is ok, But then continue to go to DE store. The problem happened. DE store it reuses view of pdp.twig of AT store. You can see the record below to understand better https://www.loom.com/share/4447ce95e9cc409c8366e0b8fb5393da?sid=e6a77971-18bd-40d2-b87e-a43ff53f3790
@mammoth-ram-1172 Is there something wrong?
m
That’s weird and I think it’s a twig’s cache issue as AT should read from the default theme and not from the DE folder. you haven’t mentioned what version you’re using
a
m
ok, So, you’re using 202212.0-p2 version
a
202212.0-p2
We have tried on the course link from here https://github.com/spryker-academy/frontend-forbackenddev-course. git clone code. The result is still the same, the error still occurs
hi @mammoth-ram-1172 Which version should we checkout to avoid errors? Can you give me an advice?
m
I will test the code again for 202212.0-p2 and the latest one 202307. The source code from the course is the same I used for recording the course ( unless by running composer install now, some things could have been changed). I’ll let you know ASAP.
👀 1
I took a look at the code in the case of the twig template, it is the controller action that hard codes the template:
public function detailAction(array _$productData_, Request _$request_)
{
_$viewData_ = $this->executeDetailAction(_$productData_, _$request_);
return $this->view(
_$viewData_,
$this->getFactory()->getProductDetailPageWidgetPlugins(),
'@ProductDetailPage/views/pdp/pdp.twig',
);
}
If we copy also the controller folder into ProductDetailDE ( do not forget to change the namespace on top of the controller) and override the parent’s detail action so as to change the template:
public function detailAction(array _$productData_, Request _$request_)
{
_$viewData_ = $this->executeDetailAction(_$productData_, _$request_);
return $this->view(
_$viewData_,
$this->getFactory()->getProductDetailPageWidgetPlugins(),
'@ProductDetailPageDE/views/pdp/pdp.twig',
);
}
Then the
ProductDetailPageDE/views/pdp/pdp.twig
is loaded and it doesn’t interfere with the one from the default. Also the twigcachewarmer builds the template’s array correctly. It’s hard to trace what changed ever since but with this solution, it works up until the latest version. If you use the newest one, 202307, then you have to change the getDefaultBucket() in SprykerConfig folder under src, to return the APPLICATION_STORE and add DE and AT to de codebucket array: return [ ‘DE’, ‘EU’, ‘US’, ‘AT’ ]; then you have to also customize:
public function getDefaultCodeBucket(): string
{
return _APPLICATION_STORE_;
if ($this->isAcpDevOn()) {
return _APPLICATION_STORE_;
}
_$codeBuckets_ = $this->getCodeBuckets();
return defined('APPLICATION_REGION') ? _APPLICATION_REGION_ : reset(_$codeBuckets_);
}
By default, it’ll return the first code bucket if no _`APPLICATION_REGION`_ is defined. Code buckets are not bound to stores, so, you’d have to return the APPLICATION_STORE as the default code bucket if you want to use stores as cod buckets. The function is deprecated as with multi stores feature, it would be managed in a different way
a
Great, Thanks for your energetic support, Yes, I found it worked well according to your instructions. However, I think this is just a temporary fix. Will it be updated to the main repo in the future.
m
Yes, I’ll be updating the course’s repo with the latest version and solution. Thanks for following the course and pointing out these issues!
a
hi @mammoth-ram-1172 It seems to affect another issue. When I add a "new-component-counter" component to the page-layout-main only in the green theme. I have checked on the DE store of the pdp site it works fine, but on the AT store it shows the content of the component. I hope that on the AT store, there will be no "new-component-counter" component. Because I only added the component on the green theme, it should only appear on the green theme. And when I do the opposite. Clear cache and go to AT store of pdp page the component content doesn't appear and then go to DE store, component content still doesn't appear. I have tests that seem to be using the same twig cache for which store is run first. You can see the record below to understand better: https://www.loom.com/share/91e51d01bea24d22871fc493948a52d6?sid=eed4c3fc-fa68-4d03-adea-81f19279f587
m
Yes. The issue is that the cache doesn’t take the code bucket into consideration. We can override , in TwigDE/TwigConfig, the cache path:
public function getDefaultPathCache(_$application_ = _APPLICATION_): string
{
return sprintf(
'%s/src/Generated/%s/Twig/DE/.pathCache',
_APPLICATION_ROOT_DIR_,
ucfirst(strtolower(_$application_)),
);
}
you can see that in the parent method:
public function getDefaultPathCache(_$application_ = _APPLICATION_): string
{
return sprintf(
'%s/src/Generated/%s/Twig/codeBucket/.pathCache',
_APPLICATION_ROOT_DIR_,
ucfirst(strtolower(_$application_)),
);
}
there is the codeBucket part of the path which could be a sign that the intention was to render the path dynamic by using codebucket. Give it a try! I tried and it works and we don’t have to override the controller’s method.
a
hi @mammoth-ram-1172, It's work fine for me. Thanks you very much