Django include template show no data - django

I am trying to include a html file, into my course page , but when i add the code it show just first tag that is h3 and don't show other data why ?
the code : {% include 'android/side_bar_good_posts.html' %}
note : i have added this code in other pages in my website and it work and show all data but in this page course it don't show anything else ( most read articles ) word

Related

How to include Service-Menu in Sidebar Navigation?

I've tried to include the service-menu-block into the twig file of the sidebar, which is loaded in category-pages, but for some reason the this doesn't work. its the same code, thats works in the footer section. If I write some static html in there it shows, but but the pages from the menu aren't listed. could somebody help out?
This is the code from the service menu:
{% sw_include '#Storefront/storefront/layout/navigation/my-service-menu.html.twig'%}
The footer navigation content, i assume thats the content you want to display inside your category page sidebar, is only loaded during the FooterPageletLoader and added during the GenericPageLoader to the page.footer variable for twig.
You can test that by adding {{ dump(page.footer) }} to the template where you wanted to include the service menu. If the dump is empty, your current page is not using the GenericPageLoader or does not have access to the data. If the dump is not empty, the required data for the template might need to be passed differently. For example:
{% sw_include '#Storefront/storefront/layout/navigation/my-service-menu.html.twig'' with {
data: page.test
} %}
Shopwares GenericPageLoader can be injected if its missing from your Controller/PageLoader. In my example, MyPageStruct extends Struct and provides just one function.
public function __construct(
private readonly GenericPageLoaderInterface $genericLoader
) { }
public function load(Request $request, SalesChannelContext $salesChannelContext): MyPageStruct
{
$page = $this->genericLoader->load($request, $salesChannelContext);
$page = MyPageStruct::createFrom($page);
$page->setDataFunction();
return $page;
}
Complete examples can be found in shopwares core code: Shopware\Storefront\Page\Account\Login\AccountLoginPageLoader

Is it possible to display the HTML provided by the admin panel app on-site?

I've built a site where I can create new posts (essays) by the admin panel. The output is visible to users. But when I place some HTML as content in the form it doesn't render itself on the page.
example:
Output on the page (with marked unrendered HTML):
I would like to know how to fix it and also, how to name the topic I want to know ( I couldn't find anything related to my problem, probably because I don't know how to express it).
Additionally, I just start to wonder if there is one more problem nested inside. How to link CSS from the static folder having this HTML mentioned above?
Django offer the autoescape template in the builtins tags
{% autoescape off %}
{{ myhtml }}
{% endautoescape %}
But your logic seems wrong, you don't need to create a new page with the doctype, just create a base template and use the block content tag to insert your article.
In your base template replace the description and title of your page by variables that will be populated by the article data.
You need to learn the basic of Django https://docs.djangoproject.com/en/4.1/ trust me you won't regret it !

In Django, is there a better alternative to using "include" 100+ times in the same document?

I made a Django site that lets users search a database and then display results. Each result is an article and for each article you see the title, author, publication date, etc. This information for each result appears in a box I created with CSS to make the result look nice. Since I may alter the look of the box in the future, I want to use it as a template and then "include" it in my results page. But because there could be over 100 results and each result will display the box, I would need to "include" the box over 100 times with code like the following:
{% for article in article_results %}
{% include 'result_box.html' %}
{% endfor %}
Is this ok? Is there a better way to do this?
Yes. See this documentation:
https://docs.djangoproject.com/en/1.11/ref/templates/builtins/#cycle
You can loop through each element passed into your template and generate some HTML depending on it's characteristics.

Adding extra tag field to Django Wagtails StreamBlock

I am trying to add an H1 tag option to Wagtails StreamBlock and although it adds it as a selection, I am not getting expected results in the browser; the H1 tag is not being created.
Here is my code
class DemoStreamBlock(StreamBlock):
h1 = CharBlock(icon='title', classname='title')
h2 = CharBlock(icon='title', classname='title')
...
And the result in the browser is shown in the screenshot below. I know I am missing something simple - any help would be appreciates. Thank you.
Totally forgot the streamfield.html file in my includes folder. Just add
{% if child.block_type == 'h1' %} <h1>{{ child }}</h1>

Use custom tags in database content

I am creating a custom CMS, with the purpose to learn more about Django.
What I'm trying to achieve is the use of tags in database content. I have a dynamic amount of placeholders attached to a page. Each placeholder can contain tags, like "current_time".
In the template I'm going to output the placeholder like this:
{% placeholder sidebar %}
And in the admin I want to do this:
This is the sidebar, the time is {% current_time "%Y-%m-%d %I:%M %p" %}
Well, the outputting is working, but the "current_time" tag isn't parsed. It's displayed as plain text. I have been looking for hours for a solution; tried regular tags, inclusion tags, simple tags, numerous snippets. But as you might guess, I still haven't found a solution.
Can anyone point me in the right direction?
Process the text as a template.