How can I add custom CSS blocks to templates or custom stylesheet?
How can I add custom CSS blocks to templates or custom stylesheet?
Unfortunately, only inline styles like in your point #1 are currently allowed within the MessageML specification.
One way to mitigate this is to use a templating engine so that style definitions can be reused.
```html
<!-- resources/hello.jinja2 -->
<div style="{{ styles.abc }}">hello</div>
<div style="{{ styles.def }}">goodbye</div>
<div style="{{ styles.abc }}">hello again</div>
```
```python
from jinja2 import Template
...
@activities.slash("/hello")
async def hello(context: CommandContext):
styles = {
"abc": "background:blue",
"def": "background:red"
}
template = Template(open('resources/hello.jinja2').read(), autoescape=True)
message = template.render(styles=styles)
await bdk.messages().send_message(context.stream_id, message)
```
Not the most elegant solution but hopefully it might help a little.
Unfortunately, only inline styles like in your point #1 is currently allowed within the MessageML specification.
One way to mitigate this is to use a templating engine so that style definitions can be reused.
```html
<!-- resources/hello.jinja2 -->
<div style="{{ styles.abc }}">hello</div>
<div style="{{ styles.def }}">goodbye</div>
<div style="{{ styles.abc }}">hello again</div>
```
```python
from jinja2 import Template
...
@activities.slash("/hello")
async def hello(context: CommandContext):
styles = {
"abc": "background:blue",
"def": "background:red"
}
template = Template(open('resources/hello.jinja2').read(), autoescape=True)
message = template.render(styles=styles)
await bdk.messages().send_message(context.stream_id, message)
```
Not the most elegant solution but hopefully it might help a little.
How can I add custom CSS blocks to templates or custom stylesheet?
How can I add custom CSS blocks to templates or custom stylesheet?
Unfortunately, only inline styles like in your point #1 is currently allowed within the MessageML specification.
One way to mitigate this is to use a templating engine so that style definitions can be reused.
```html
<!-- resources/hello.jinja2 -->
<div style="{{ styles.abc }}">hello</div>
<div style="{{ styles.def }}">goodbye</div>
<div style="{{ styles.abc }}">hello again</div>
```
```python
from jinja2 import Template
...
@activities.slash("/hello")
async def hello(context: CommandContext):
styles = {
"abc": "background:blue",
"def": "background:red"
}
template = Template(open('resources/hello.jinja2').read(), autoescape=True)
message = template.render(styles=styles)
await bdk.messages().send_message(context.stream_id, message)
```
Not the most elegant solution but hopefully it might help a little.
Unfortunately, only inline styles like in your point #1 is currently allowed within the MessageML specification.
One way to mitigate this is to use a templating engine so that style definitions can be reused.
```html
<div style="{{ styles.abc }}">hello</div>
<div style="{{ styles.def }}">goodbye</div>
<div style="{{ styles.abc }}">hello again</div>
```
```python
@activities.slash("/hello")
async def hello(context: CommandContext):
styles = {
"abc": "background:blue",
"def": "background:red"
}
template = Template(open('resources/hello.jinja2').read(), autoescape=True)
message = template.render(styles=styles)
await bdk.messages().send_message(context.stream_id, message)
```
Not the most elegant solution but hopefully it might help a little.
How can I add custom CSS blocks to templates or custom stylesheet?
Unfortunately, only inline styles like in your point #1 is currently allowed within the MessageML specification.
One way to mitigate this is to use a templating engine so that style definitions can be reused.
```html
<div style="{{ styles.abc }}">hello</div>
<div style="{{ styles.def }}">goodbye</div>
<div style="{{ styles.abc }}">hello again</div>
```
```python
@activities.slash("/hello")
async def hello(context: CommandContext):
styles = {
"abc": "background:blue",
"def": "background:red"
}
template = Template(open('resources/hello.jinja2').read(), autoescape=True)
message = template.render(styles=styles)
await bdk.messages().send_message(context.stream_id, message)
```
Not the most elegant solution but hopefully it might help a little.