Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template variables' delimiter '%' conflicts with inline CSS #300

Closed
aharshac opened this issue Dec 8, 2017 · 10 comments
Closed

Template variables' delimiter '%' conflicts with inline CSS #300

aharshac opened this issue Dec 8, 2017 · 10 comments
Labels

Comments

@aharshac
Copy link

aharshac commented Dec 8, 2017

Hi @me-no-dev
Thank you for an impressive library.

I'm trying to use a template processor on a file from SPIFFS. That file has inline CSS with '%' characters. The template processor considers any text including line breaks and whitespaces as templates. Entire chunks of CSS and other HTML markup are replaced by the default case of the template processor function.

For example, in the snippet below,

<div style="background:#fff;height:50px;width:100%;display:flex;justify-content:center;align-items:center;z-index:90;position:absolute;top: 0;">
            <div style="width:100%;height:100%;display:flex;flex-direction:column;justify-content:center;align-items:left;">

;display:flex;justify-content:center;align-items:center;z-index:90;position:absolute;top: 0;"> <div style="width:100 is considered as a template variable.

Is it possible to not consider spaces while processing templates? Or rather, have an option to change the template variable delimiter?

@atanisoft
Copy link
Contributor

@aharshac you can change the template char from % to another single character here: https://github.com/me-no-dev/ESPAsyncWebServer/blob/master/src/WebResponseImpl.h#L62

What might be good is switch from %VAR% to something like {VAR} instead with unique open/close characters around the variable name. This would likely be less problematic in HTML files (hopefully).

@aharshac
Copy link
Author

aharshac commented Dec 8, 2017

@atanisoft I've changed the template character to tilde ~. Thank you.

While changing the template format or delimiter character would be excellent, simply avoiding text with spaces between two consecutive % is good enough for most cases.

@stale
Copy link

stale bot commented Sep 21, 2019

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 21, 2019
@stale
Copy link

stale bot commented Oct 5, 2019

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Oct 5, 2019
@chupocro
Copy link

This shouldn't be closed because not being able to use the percent character in the CSS templates makes template processing unusable. I've just spent 5 hours debugging the firmware because of that problem.

@matrn
Copy link

matrn commented Sep 14, 2022

Any updates to this issue? There is no readable ASCII character that cannot be normally contained in the html file so changing TEMPLATE_PLACEHOLDER is not a solution. It would be handy if more than one character in the separator will be supported and also start & end separator (for example for this {{var}}).

@zekageri
Copy link

zekageri commented Sep 14, 2022

Open and close brackets would be the best approach

@DeeEmm
Copy link

DeeEmm commented Nov 17, 2022

@zekageri & @matrn

I agree. Open / close tagging along with double delimiters is standard practice for templating engines.

Using a single character is ALWAYS going to create an issue for someone. Using a common valid character like % is a really poor choice.

It would not be too bad if that single character was user definable, at least the end user could change it on a case-by-case basis, but it's not possible to change it without hacking the core which means that it is not really a valid solution.

/DM

@LondonJammo
Copy link

Still an issue, and % is still breaking the code. Was a fix/workaround found at all?

@zekageri
Copy link

zekageri commented Apr 7, 2023

This lib is still not maintained anymore. If you want to change it, you need to tweak the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants