Crispy forms CheckboxSelectMultiple display inline - django-crispy-forms

I am having a lot of difficulty getting a MultipleChoiceField list to display inline using crispy. I have tried adding div's between by displaying the form using
{{ for field in form }}
but it places the div's between each selectbox AND the select boxes label.
This is where I create the CheckboxSelectMultiple:
preferred_topics = forms.MultipleChoiceField(choices=TOPICS, required=False, widget=forms.CheckboxSelectMultiple())
And I am printing it out with:
{{ form|crispy }}
I also have many other form types before and after this field (text boxes etc)
Thank you.

You will probably need to use the {% crispy %} tags and FormHelper. This will allow you to use InlineField.
There is also the table option which doesn't use divs.

Related

How to allow HTML to pass through a set block with Nunjucks

I'm really excited to see that we can apply a block assignment for set through Nunjucks. What would be the correct way to allow HTML to be passed through this approach?
I want to do the following from my initial nunjucks file:
{% set demoSetBlock %}
<div class="mClass">
<p>a header value in a nunjucks set block</p>
</div>
{% endset %}
I then want to call it into my nunjucks template like so...
{{demoSetBlock}}
but...it's printing out the content along with the HTML markup on the web page, just like this...
<div class="mClass"> <p>a header value in a nunjucks set block</p> </div>
How can we render this so that it shows it as...
a header value in a nunjucks set block
Not sure if this is the official way of resolving the situation, but what appears to be working for me now is using |safe as an attribute when the set block is called, like so:
{{demoSetBlock|safe}}
as a result, my HTML is perfectly rendered on the browser.
This is helpful in cases
when I don't want to depend on macros.
when I want to depend on set as an instrumental component for defining and passing data through various parts of my templates.
where I have other include files (i.e. _include-header.njk, _include-footer.njk) that are directly attached to my main template file. I could then use set block for one of these files.

Using ckeditor i have stored description but in view i got the data with <p> tag how can i solve it?

When I am storing something using ekeditor in my Laravel project, I got the data in view the data with a <p> tag. How can I store my data without a <p> tag
Result:
<p>good<\p>
Expected result:
good
use textarea instead of CKEditor if you don't want tags to be stored.
otherwise, you can try this.
if you use {{ $data->xyz }} , it will show texts with tags. So use {!! $data->xyz !!} , it won't show tags but will convert in html codes.

Troubles with HTML-tags in post content in octobercms frontend

I'm trying to display my terms' content on the page using component 'TermsDescription'.
I try this code on my page :
<...> {% component 'TermsDescription' %} <...> {% component 'TermsDescription|raw' %} <...>
But display same as screen-shot
my content is displayed with <.p> tag. So, tags displayed as text, not as HTML-tags at all. I have either 'only text' without decoration, or pure tags-as-a-text on the page. What am I missing? Where is the solution? :)
You can not use raw in defining component like this {% component 'TermsDescription|raw' %}.
Instead of this, you should have to understand the components in OctoberCMS.
Suppose you are passing data from your TermsDescription component.
$this->page['data']= /Data::find($id);
And it contains title and description. And Description has data as seen in your question.
Then you can do this way
{{ data.description|raw' }} where you want to print description.

Jekyll, include markdown with layout in html

I have a website that consists out of a few 'slides'. Each has a fixed structure, used by some scripts, but variable content. I'm hosting it on github and am now trying to use Jekyll to make it easier to add new slides.
I already have each slide in a different html file, which I include in the main page: {% include_relative _slides/about.html %}. Now I'm trying to make it a markdown file, and I wanted to use front matter to make a layout that each slide's file could use. I can include a markdown file, and get it to render by doing:
{% capture myInclude %}{% include_relative _slides/test.md %}{% endcapture %}
{{ myInclude | markdownify }}
However, when I add a front-matter block to it with a layout defined in it, the layout doesn't get applied. It just gets rendered as a horizontal line (for the first ---) and then "layout: slide title: Test Slide —" in plain text.
Is there any way to fix this? Or perhaps a better way to break up my index.html and the slides in it?
Thanks a lot!
Note: Sorry if this was asked before, I Googled everything I could imagine it would be called.
I found something that works for me. I divided my template in two parts, the part above the content, and the part under it. Then in the file I include, there are two includes as well, one at the top and one at the bottom.
So my 'slide' files look like this:
{% include slide_start.html title="About" image="images/about.jpg" %}
... the content of the slide ...
{% include slide_end.html %}
As you can see, in the first include I give some parameters, these will be filled in and can be accessed with the liquid tags {{ include.something }}.
My slide_start.html looks like:
<div class="slide">
<div class="header">
<span>{{ include.title }}</span><!-- no whitespace
--><img src="{{ include.image }}" alt="{{ include.title }}"/>
</div>
<div class="content" markdown="1">
the slide_end.html is just two closing div tags.
You're trying to mix the page/post and the include strategies.
Page/post have a front matter and are decorated with a template, which can itself be decorated. `mypage.html -> layout: page -> layout: default.
Includes are included in page/post but they are only code parts. They cannot be decorated with a template.
You will have to choose.
Take a lool at https://github.com/shower/jekyller this can be helpfull.

Changing Laravel Blade Delimiter

I know that you can change the default blade delimiter using
Blade::setEscapedContentTags('[[', ']]');
Blade::setContentTags('[[[', ']]]');
However I don't know where should I put it so that it only affect single blade template as opposed to putting it at app/start/global.php which affect whole application.
If you only want to use different tags for a single view, you can set the tags in the closure or controller action that will generate the view.
Route::get('/', function()
{
Blade::setEscapedContentTags('[[', ']]');
Blade::setContentTags('[[[', ']]]');
return View::make('home');
});
This could be an issue if you want to use the normal tags {{ and }} in an application layout but your custom ones in a nested view - I'm not sure what the best approach there would be.
The solution with Blade::setEscapedContentTags / Blade::setContentTags doesn't work in the latest versions of Laravel (checked at 5.6).
The recommended approach is (https://laravel.com/docs/5.6/blade#blade-and-javascript-frameworks):
Blade & JavaScript Frameworks
Since many JavaScript frameworks also use "curly" braces to indicate a
given expression should be displayed in the browser, you may use the #
symbol to inform the Blade rendering engine an expression should
remain untouched. For example:
Hello, #{{ name }}.
In this example, the #symbol will be removed by
Blade; however, {{ name }} expression will remain untouched by the
Blade engine, allowing it to instead be rendered by your JavaScript
framework.
The #verbatim Directive
If you are displaying JavaScript variables in
a large portion of your template, you may wrap the HTML in the
#verbatim directive so that you do not have to prefix each Blade echo
statement with an # symbol:
#verbatim
<div class="container">
Hello, {{ name }}.
</div>
#endverbatim
Simply use #verbatim directive.wrap your whole code in it and blade will just ignore all the curly braces.

Resources