Skip to content

Commit

Permalink
Merge branch '5.2' into compile-all-use-configured-locales
Browse files Browse the repository at this point in the history
  • Loading branch information
javihgil committed Jun 20, 2024
2 parents e037240 + 41f3ac3 commit e923a8f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"require-dev": {
"doctrine/data-fixtures": "^1.6",
"doctrine/doctrine-fixtures-bundle": "^3.4",
"friendsofphp/php-cs-fixer": "3.58.*",
"friendsofphp/php-cs-fixer": "3.59.*",
"google/cloud-storage": "^1.30",
"phpstan/phpstan": "^1.10.49",
"phpunit/phpunit": "^11.0",
Expand Down
15 changes: 15 additions & 0 deletions docs/15_troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,18 @@ sfs_cms:
content:
prefix_compiled: '%env(APP_VERSION)%/'
```
## Some site or locale content render has not styles or scripts
When a content is saved or republished, the content is compiled and stored in database. This content includes styles and scripts references.
If you use webpack encore, when an asset reference is rendered in a request, it won't be rendered again in the same request.
SfsCms manage the _default webpack entrypoint, and automatically reset the entrypoint when a content is rendered.
If you use a custom entrypoint, you need to reset the entry for the site or locale to force the assets to be recompiled before using it.
```twig
{{ sfs_cms_encore_entry_reset('blog') }}
{{ encore_entry_link_tags('blog-styles', null, 'blog') }}
```
31 changes: 31 additions & 0 deletions src/Twig/Extension/WebpackExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Softspring\CmsBundle\Twig\Extension;

use RuntimeException;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollectionInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class WebpackExtension extends AbstractExtension
{
public function __construct(protected ?EntrypointLookupCollectionInterface $entrypointLookupCollection = null)
{
}

public function getFunctions(): array
{
return [
new TwigFunction('sfs_cms_encore_entry_reset', [$this, 'webpackResetEntrypoint']),
];
}

public function webpackResetEntrypoint(string $entrypointName = '_default'): void
{
if (!$this->entrypointLookupCollection) {
throw new RuntimeException('Webpack encore entrypoint lookup collection is not available');
}

$this->entrypointLookupCollection->getEntrypointLookup($entrypointName)->reset();
}
}
2 changes: 2 additions & 0 deletions templates/admin/content/preview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,7 @@
</div>
</main>
</div>

{% include '@SfsComponents/flash-messages/alerts.html.twig' %}
{% endblock body %}

0 comments on commit e923a8f

Please sign in to comment.