Twig icon indicating copy to clipboard operation
Twig copied to clipboard

Add base64_encode twig filter

Open alexander-schranz opened this issue 8 months ago • 2 comments

I'm using base64_encode a few times to bring data from backend to my JS code where it only is encoded on click, also binary strings of svg can be base64 encode for data string in img.

alexander-schranz avatar Apr 24 '25 11:04 alexander-schranz

For data URIs, we already have an existing data_uri filter in the twig/html-extra package (which takes care of everything needed, not just performing base64 encoding.

stof avatar Apr 24 '25 11:04 stof

For data URIs, we already have an existing data_uri filter in the twig/html-extra package (which takes care of everything needed, not just performing base64 encoding.

I'm using it outside of data_uri usage. Really just data-my="{{ privateText|base64_encode }}". But nice to see there is data_uri which we can then reference in the docs also.

alexander-schranz avatar Apr 24 '25 11:04 alexander-schranz

I'm not sure the use cases are common enough to justify having it in core.

fabpot avatar Nov 07 '25 07:11 fabpot

@fabpot but would it hurt :)?

alexander-schranz avatar Nov 07 '25 08:11 alexander-schranz

We're trying to limit the number of core features to the ones that are useful for "many" apps. This is always subjective of course, but as Twig is mature now, I'm more strict about what we had.

fabpot avatar Nov 07 '25 09:11 fabpot