0

Hi everyone I create a app with 3 fields (html, css and js) the apps have to embed this 3 fields in the template of my app like this. I use a placeholder to show this fields.

<style type="text/css">
  {{instance.css_code|safe}}
</style>


{{instance.html_code|safe}}


<div id="containerChart" style="height: 400px; min-width: 310px"></div>

<script type="text/javascript">
  {{instance.js_code| safe }}
</script>

What a best way to do that, for example load the javascript code in the footer (with the rest of the javascript code) and in the header the css code

Like for example if my placeholder has element load the field js in the footer..etc

It is posible!

Thanks in advance.

2 Answers 2

3

I use sekizai tags to achieve this functionality.

In my plugin template, I've got something like this:

{% load sekizai_tags %}
{% addtoblock "css" %}
<style type="text/css">
/* CSS */
</style>
{% endaddtoblock %}
{% addtoblock "js" %}
<script type="text/javascript">
// javascript
</script>
{% endaddtoblock %}

<!-- Rest of your HTML markup -->

Then, in the base.html, I've got this for the CSS (in the head):

{% render_block "css" postprocessor "cnk_ft1_cms.sekizai_processors.spaceless_post_processor" %}

And this for the JS (for the footer):

{% render_block "js" %}

In my case I am also processing the CSS as well. You can position the addtoblock elements anywhere in your template HTML. Also, chances are that you already have the sekizai tags set up in the base template (as it's used by Django CMS as well).

Sign up to request clarification or add additional context in comments.

Comments

0

Not clear with your question, do you want to load static files or you want something else https://docs.djangoproject.com/en/1.10/howto/static-files/#managing-static-files-e-g-images-javascript-css

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.