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
Related
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 !
I have been able to build a simple CRUD app for a project using the Symfony EasyAdminBundle and it has worked great for the normal entity based use cases. I have some additional use cases though where I want to do things like rebuilding data. For these I have to capture certain request attributes, pass over to a controller and then delegate to a backend API call to a remote service.
This can all be done in Symfony but I am running into trouble with how to wire this into the EasyAdmin view/method of working. Ideally I want this to be a page inside easy admin and not lose the left menu etc. So far, the only way I have found to do this is to create a Model class what is using one of the existing tables but has only some properties I would need to drive into the API. I then override the controller actions so rather than do a default save, I handle against that remote API.
The problem with this approach is that obviously I am now bound to Doctrine entities and that would be problematic for requests that were not mappable to the database.
Is there a way to define a logical entity that would let me leverage associations so I can have lookups etc, that will wire into the bundle seamlessly, but are not actually tied to a backend database table or view?
I am adding my response for people who may still face this issue in the future.
How I solved this without creating an entity :
Create a custom controller: symfony console make:controller
Edit the controller's view to inherit the EasyAdmin layout :
{# ./src/templates/home/index.html.twig #}
{% extends '#EasyAdmin/Default/layout.html.twig' %}
{# Let\'s remove/empty the header #}
{% block content_header_wrapper %} {% endblock content_header_wrapper %}
{# The main page content block #}
{% block main %}
**PUT YOUR CODE HERE**
{% endblock main %}
{# Let\'s remove/empty the footer #}
{% block content_footer_wrapper %} {% endblock content_footer_wrapper %}
Add your page to the side navigation
design:
menu:
- {route: 'home', label: 'Home', default: true, icon: 'home'}
- {entity: 'MyEntity', label: 'My Relevant Entity', icon: 'briefcase'}
I'd solve this problem creating a custom action as explained here (probably you want a route-based action) and then use a template that extends from #EasyAdmin\default\layout.html.twig or any other default template similar to what you want to achieve.
Here is solution:
{# easy_admin/form.html.twig #}
{% block _product_custom_title_widget %}
{# ... #}
More information
{% endblock %}
Finally, add this custom theme to the list of themes used to render backend forms:
easy_admin:
# ...
design:
form_theme:
- 'horizontal'
# the following Twig template can be located anywhere in the application.
# it can also be added to the twig.form_themes option to use it in the
# entire application, not only the backend
- 'easy_admin/form.html.twig'
Here is link for more information: https://symfony.com/doc/master/bundles/EasyAdminBundle/book/edit-new-configuration.html
Easyadmin is a bundle and you can customize all the pages of any bundle.
This logic applies to any template that lives in a bundle: just follow the convention: app/Resources/{BUNDLE_NAME}/views/{PATH/TO/TEMPLATE.html.twig}.
Suppose you've installed an imaginary open-source AcmeBlogBundle in your project. And while you're really happy with everything, you want to override the template for a blog list page. Inside the bundle, the template you want to override lives at Resources/views/Blog/index.html.twig.
To override the bundle template, just copy the index.html.twig template from the bundle to app/Resources/AcmeBlogBundle/views/Blog/index.html.twig (the app/Resources/AcmeBlogBundle directory won't exist, so you'll need to create it). You're now free to customize the template.
Reference: https://symfony.com/doc/3.4/templating/overriding.html
I have read the question here regarding the general case, but I am interested in how to do this in Django. I am assuming it will be a combination of code in view and template.
Excessive details:
More specifically I do not want to include top menu and footer if the page is loaded in iframe (using lightbox). For now I check the flag in template:
{% block header %}
{% if not lightbox %}{{ block.super }}{% endif %}
{% endblock header %}
which I have set in the view based on the url where the page is opened from:
if http_referer and http_referer.__contains__("/specific/page/"):
context["lightbox"] = True
This is obviously not flexible. For example I have a link to contact details in the footer shown on every page. If a user clicks on it, an iframe is opened with lightbox (here I do not want to see the footer and top menu in iframe again). But if the user opens the link in a new tab, I want there to be the footer and top menu for easier navigation and style consistency. Notice that in both case the user is opening the link from the same page. Thus the above solution does not work.
Edit:
#dotcomly The question you suggested as duplicate is very similar but not helpful in my case as I strictly want to use the same url (like described above) and change the content depending on context (if the content is loaded in iframe or main window). The (accepted) answer to the other question suggests using different urls which is not acceptable in my case.
Temporarily I solved my problem by adding the following script to the template of the pages that may be loaded in the iframe:
<script type="text/javascript">
function inIframe () {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
if(inIframe()) {
$('header').css('display', 'none');
$('footer').css('display', 'none');
// or anything else you may want to do
}
</script>
I've got a django-cms site on which I have created a page at /managers-home/ with an app hook so that I can use myapp from that page.
myapp renders various templates at various URLs beneath /managers-home/ and I would like each of these templates to have a section editable via the django-cms content plugin. Therefore I have added {% staticplaceholder "content" site %} to these templates, because, as I understand it, you can't use a standard {% placeholder "" %} from within a hooked application.
I made a start with this and added some text to the placeholder on /managers-home/page-1/ which uses page-1.html and then when I got to the placeholder on /managers-home/page-2 I could already see the content from page-1 despite now using page-2.html so the placeholder on these two individual templates is being shared.
How can I correctly add django-cms placeholders throughout my application templates?
Turns out my problem was that a static_placeholder is exactly that, just a placeholder identified by the name given and anywhere you reference that name you get the same content.
So in order to allow each of my templates to display custom text, I've created a static_placeholder for each template.
# page-1.html
{% static_placeholder "page-1" site or %}
Default text goes here
{% endstatic_placeholder %}
# settings.py
CMS_PLACEHOLDER_CONF = {
'page-1': {
'plugins': ['TextPlugin', 'UploadedPicturePlugin'],
'text_only_plugins': ['LinkPlugin'],
'extra_context': {"width": 640},
'name': gettext("Content"),
}
}
I want to add a common sidebar for all my templates on my site. Let's say, I want a picture and some text, that the final user could modify whenever she feels like without having to mess with my base.html template (the base class of all my templates).
To be clear, I know that I can put plugin place holders with the template tag:
{% placeholder sidebar %}
My problem is that if I have five 5 templates and the content of the sidebar is the same for all of them, the user have to go through all the pages and change them one by one.
On the other hand, it cannot be static because I want the user to be able to modify the content through the admin.
Specifically, I am trying to do this with the cmsplugin-contact which saves me the troubles of configuring forms and emails.
You can create a special page that isn't published and add a "sidebar" placeholder to the template. You then use the {% show_placeholder %} template tag to render that sidebar placeholder in the base template that each of your 5 other pages are using