miguelgrinberg/microblog

How to solve the syntax conflict between JinJia2 and CSS in chapter 21.3 ?

JTP-123 opened this issue · 6 comments

I met such a question that JinJia2 used in CSS inline style will cause a conflict that the default block string will be misunderstood as a css property value in visual studio code . The detail is :

<span id='message_count' class="badge"
            style="visibility: {% if new_messages %}visible
            {% else %}hidden {% endif %};">

I happend to find a related plausible solution that is to set app.jinja_env.block_start_string = '(%', this solution asks me to alter every existed block start string , that would be boring. So is there anyway to solve such question besides this?

Are you just concerned about the way the code is highlighted in VS Code? In that case you may want to install a Jinja extension. I don't really have experience with this, but a Google search returned https://marketplace.visualstudio.com/items?itemName=samuelcolvin.jinjahtml. Hopefully that works.

Are you just concerned about the way the code is highlighted in VS Code? In that case you may want to install a Jinja extension. I don't really have experience with this, but a Google search returned https://marketplace.visualstudio.com/items?itemName=samuelcolvin.jinjahtml. Hopefully that works.

The above code will be shown in VS Code like this:
批注 2023-02-27 114326

As I explained, this is not a problem, it's just that VS Code does not understand the Jinja template syntax. Have you tried installing a Jinja plugin?

As I explained, this is not a problem, it's just that VS Code does not understand the Jinja template syntax. Have you tried installing a Jinja plugin?

Oh, i made a mistake, thank you for your reply. By the way, i have installed Better JinJa, but it seems that this plugin changes nothing, did i miss some key step?

I'm not sure if you made a mistake or not. As I said above, I'm not familiar with the Jinja plugins available for VS Code, so I don't know how they are used, or if they need some special configuration.

My opinion is that this can be ignored. As I said above, this isn't an error in your application, it's just that VS Code does not understand the Jinja template syntax.

I'm not sure if you made a mistake or not. As I said above, I'm not familiar with the Jinja plugins available for VS Code, so I don't know how they are used, or if they need some special configuration.

My opinion is that this can be ignored. As I said above, this isn't an error in your application, it's just that VS Code does not understand the Jinja template syntax.

ok, now that it is not a problem, i will leave aside it. thank you for your reply, sincerely.