symfony-docs icon indicating copy to clipboard operation
symfony-docs copied to clipboard

A question on the AssetMapper component

Open programarivm opened this issue 9 months ago • 6 comments

Hi there,

Here's a question on the AssetMapper component just in case the following issue is not documented.

I was wondering if it is possible to "compile" the assets without versioning the files so that the file names generated in the public folder are still the exact same ones as in the asset folder.

Please correct me if wrong, this way the assets could be referenced in Markdown files. See https://github.com/twigphp/Twig/discussions/4070

Thanks for the help.

programarivm avatar May 06 '24 16:05 programarivm

No it's not possible for now sorry

smnandre avatar May 08 '24 21:05 smnandre

What about using a command option?

php bin/console asset-map:compile --unversioned

programarivm avatar May 09 '24 13:05 programarivm

If you need to deploy unversionned asset you still can use the Asset component !

smnandre avatar May 10 '24 11:05 smnandre

Sorry, I wasn't able to find any documentation on how to "compile" the assets so that the hash won't be appended to the filenames. Can you please provide an example command for this?

🙏 Thank you!

programarivm avatar May 10 '24 13:05 programarivm

If you need to compile assets via asset mapper, today you cannot escape versionning. If you need to deploy assets to the public folder, the Asset package can do it for you.

https://symfony.com/doc/current/components/asset.html

But if your problem is related to the markdown example you gave, there is a better solution i think : render the twig file once and then call the markdown filter

So let's say you have a article.md.twig

# Title of your article

Lorem ipsum damet

[{{ article.alt }}]({{ absolute_url(asset('images/my-file.png')) }})

In another template, you can do this:

{% set content = include('article.md.html') %}

{% apply markdown_to_html %}
   {{ content }}
{% endapply %}   

smnandre avatar May 10 '24 20:05 smnandre

Thanks for the help, it is very much appreciated! I just created a folder called public/blog for my static blog images. It seems as if the simplest solution is to put the blog images in the public directory as opposed to the assets directory for them to then be referenced in the Markdown documents. See templates/post.html.twig

programarivm avatar May 13 '24 10:05 programarivm

Let's close this one as "fixed" because it looks like a particular use-case and some clues and guidelines were provided. Thanks!

javiereguiluz avatar Jun 13 '24 15:06 javiereguiluz