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

Adding Html and Jinja2 Templating #349

Open
ablashek opened this issue Sep 2, 2024 · 4 comments
Open

Adding Html and Jinja2 Templating #349

ablashek opened this issue Sep 2, 2024 · 4 comments

Comments

@ablashek
Copy link

ablashek commented Sep 2, 2024

I would ask to kindly consider adding an HTML / Jinja2 field type to Print Designer as is with the previous Document Designer. The level of flexibility given by this new tool is great and a step forward in the right directions, but a simple table doesn't give the same level of flexibility.

Possibly use cases: when user needs to loop through data and show them as wrapping components instead of row, or when user needs to show a timeline of activities.

If able to incorporate html, bootstrap, and jinja2 (or even js for that matter) the posibilities are endless in terms of design and will also reduce the burdon on the team to be consistently adding new features.

@maharshivpatel
Copy link
Collaborator

@ablashek jinja is already supported. #99 and #115

@ablashek
Copy link
Author

ablashek commented Sep 5, 2024

Thanks @maharshivpatel , understood how to use jinja watching your video. But any chance on html?

@maharshivpatel
Copy link
Collaborator

@ablashek you can pass html string inside jinja and it works 🤫

@ablashek
Copy link
Author

ablashek commented Sep 6, 2024

hi @maharshivpatel , can you give me an example of how to do this? Because i tried adding jinja2 as such:

{% for type, items in doc.raw_materials | groupby('type') %}
    {% set type_html = "<h5>" + type + "</h5>" %}
    {{ type_html | safe }}

    {% set container_start = '<div style="display: flex; flex-wrap: wrap; gap: 15px;">' %}
    {{ container_start | safe }}
    
    {% for item in items %}
        {% set item_html = '<div style="border: 1px solid #ccc; padding: 10px; width: 200px; text-align: center;">' %}
        {{ item_html | safe }}
        
        {% set img_html = '<img src="https://www.indopar.com.py' + item.image + '" alt="Image" style="object-fit: contain; height: 125px; width: 100%;">' %}
        {{ img_html | safe }}
        
        {% set content_html = '<div style="margin-top: 10px;"><strong>' + item.raw_material + '</strong><p>Cantidad: ' + item.quantity + '</p></div>' %}
        {{ content_html | safe }}
        
        {{ '</div>' | safe }}  {# Close item div #}
    {% endfor %}
    {{ '</div>' | safe }} {# Close container div #}
    
    {{ '<hr>' | safe }}
{% endfor %}]

But as soon as i leave focus it cleans up and reduces the amount of code. When I render it, I see nothing.
If you have a video tutorial or screenshot on how to implement, would be greatful. thanks!

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

No branches or pull requests

2 participants