Ckeditor "Convert the HTMLField to a Placeholderfield and configure the placeholder to only accept TextPlugin" - django-cms

Perhaps I do not understand some simple thing. I’m reading the documentation for the second day and don’t understand how to use ckeditor in django-cms, in a third-party plugin.
Here is written:
Usage as a model field If you want to use the widget on your own model
fields, you can! Just import the provided HTMLField like so:
from djangocms_text_ckeditor.fields import HTMLField And use it in
your models, just like a TextField:
class MyModel(models.Model):
myfield = HTMLField(blank=True) This field does not allow you to embed any other CMS plugins within the text editor. Plugins can only
be embedded within Placeholder fields.
If you need to allow additional plugins to be embedded in a HTML
field, convert the HTMLField to a Placeholderfield and configure the
placeholder to only accept TextPlugin. For more information on using
placeholders outside of the CMS see:
http://docs.django-cms.org/en/latest/how_to/placeholders.html
Currently HTMLField is working and after reading the instructions I don’t understand how I can "convert the HTMLfield to a Placeholder and configure the placeholder to only accept TextPlugin" in a third party plugin which was fully integrated into django-cms. I have never created placeholders in third party plugins.
My goal is so that in a third party plugin I can set a text box in which I can edit the text using formatting features. I am using the latest Django-CMS. By default, it has djangocms_text_ckeditor.
Thank you!
models.py:
[..]
from djangocms_text_ckeditor.fields import HTMLField
class Question(models.Model):
content = HTMLField(blank=True)
[..]
template
[..]
{% load cms_tags %}
[..]
{% for field in form %}
{{ field }}
{% endfor %}
[..]
My textarea looks like this:
<textarea name="content" cols="40" rows="10" class="CMS_CKEditor" data-ckeditor-basepath="/static/djangocms_text_ckeditor/ckeditor/" id="id_content"></textarea>
I noticed that through the admin panel it was possible to use the editor for this new textarea, but nothing has changed on the site for a user. Visually it is an ordinary textarea

I found the solution. I have to include the "{{ form.media }}" tag in the templates
<form method="post" enctype="multipart/form-data" novalidate>
{% csrf_token %}
{{ form.media }}
[..]

Related

How to style an Image Field button in Django App

I want to style my Image Field Button (Choose File) with CSS. Currently, its displaying in the default theme. I am using Bootstrap V5.0.1, Django V3.2.12, Python 3.7.6.
First, I tried to identify or add a class or id which I can add and style the button regularly but was unable to add as the button was added by Django Image Field. The Code in my forms.py is given below:
from django import forms
class ImageUploadForm(forms.Form):
image = forms.ImageField(label='')
Then I used the Hover functionality of the Chrome Developer Tools to identify any leads and found that the button and its area had 2 id's #file-upload-button and #id_image.
I tried to add CSS to the above-mentioned id's but did not get the result i desired. I want to style the Choose File Button Below also if possible can i add any bootstrap to the button, any help would be appreciated! Thanks.
HTML-Django Code
<div class="form-group text-center">
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form }}
<br>
<button type="submit" id="btnUpload" class="btn btn-primary" style="margin-top:20px;">Upload</button>
</form>
</div>
i was having the same problem and came upon this article https://www.quirksmode.org/dom/inputfile.html
The ideia is to create a useless button and add style to it, then overlap both with the image field button on top, and then set the opacity of the image button to 0.
The image field button will still work, but you will only see the button with the style you add.

{{ form_widget(form.fieldsName) }} raw rendering

First of all i have already searched and tried a lot of methods here but with no success.
My problem is that i have a field in my database that contains <br/>
that get displayed on twig {{form_widget(form.fieldsName)}}
I do not want them to be displayed and do there job which is break line.
thank you in advance.
{{form_widget(form.fieldsName| raw) }}
raw will escape html characters
If you want to use <br /> in form elements, you should create your own form templates. Read the docs on https://symfony.com/doc/current/form/form_customization.html
For using <br />in the content of any form field, symfony/twig is doing the right thing. But using {{form_widget(form.fieldsName| raw) }} have no sense, because form_widget is a rendering function for twig to output real, unescaped html.

How to generate thumbnails with Dropzone when using the basic way

I'm creating a Symfony 3 CRM for a property database, and I'm implementing DropZone for property image uploads. I've looked around for the answer to my question, but the solutions just say to use createThumbnailFromUrl which is all well and good, but I'm just using Dropzone using the easy method, like so:
<div id="dropzone">
<form action="{{ oneup_uploader_endpoint('property_images') }}" class="dropzone">
<input type="hidden" value="{{ property_id }}" name="id" />
</form>
</div>
I'm using oneup_uploader to actual upload the files, and then after it does this, I use a renamer class to put the image into a folder using the aforementioned property_id:
public function name(FileInterface $file)
{
$propertyId = $_REQUEST['id'];
return sprintf('%s/%s.%s',
$propertyId,
uniqid(),
$file->getExtension()
);
}
Which generates a random file name under a directory using the property ID.
Since there is no actual initialisation and I'm only using the dropzone.js from the site, I don't know how to create and name thumbnails. I need to generate cropped squares for the listings, but I am unsure where to do this - would this need to be done in the PHP as well, after the renaming happens? Or do I need to completely rethink the way I'm implementing Dropzone? Any help appreciated.
EDIT: Now implementing the stojg/crop bundle for Symfony to manually create thumbnails onUpload().

HTML tags in XML translation

How to add statements like the following one to translation (XLIFF format):
Click <a href='http://example.com'>here</a> to continue.
Could you put it in a CDATA field within the xml?
http://en.wikipedia.org/wiki/CDATA
In Twig, you can include translation and disable autoescape, but you have to keep control of its content as it could be a security lack...
{% autoescape false %}{{ 'your.translation.id'|trans }}{% endautoescape %}

Symfony2: custom HTML inside label

Is there a way with Symfony 2 forms to add HTML inside a label?
I want:
<label for="myfield"><span class="photo">My label</span></label>
How can I write it?
None of these ideas work properly as expected:
<span class="photo">{{ form_label(form.myfield) }}</span>
Or
{{ form_label(form.myfield, '<span class="photo">'~myfield~'</span>') }}
Thanks for your help,
A
Take a look to Symfony2 Form theming documentation, especially to the "Adding a "Required" Asterisk to Field Labels" section.
I am not sure this is the best way to go, but it should work.
I think you could do it like this:
enter code here
{{ form_label(form.myfield,'Name of the label') }}
{{ form_errors(form.myfield)}}
{{ form_widget(form.myfield),{attr:{'class':'photo span'}}) }}

Resources