I created view with name "centers" and render that view in twig template with {{ views_embed_view('centers', 'block_1') }}. It gives me nothing in result.
So,please anyone help me
The above module was depreciated in favour of
Twig Tweak
Twig Tweak module provides a Twig extension with some useful functions
and filters that can improve developer experience.
Ex: <dd>{{ drupal_view('centers', 'block_1') }}</dd>
hope this help you
THANKS
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 am trying to get my site url like; https://www.example.com/ in admin twig file for my custom module.
Can anyone help me please?
I tried this, but no result;
{{ HTTPS_CATALOG }}
In your corresponding controller file define:
$data['site_url'] = $_SERVER['HTTP_HOST'];
in corresponding twig file you can call this data:
{{ site_url }}
If the answer are useful for you, can you mark it "This answer is useful"
Say I have a handlebars file stored in some_directory/some_template.handlebars
I want to render this template using render command so that I can hook it up to child controller.
I've tried:
{{ render "someDirectory/someTemplate" post }}
{{ render "some_directory/some_template" post }}
none of these works. If I move some_template.handlebars to root directory, then it works when I do:
{{ render "someTemplate" }}
but I would like to avoid this since I'm finding that the root directory is getting cluttered. It's worth mentioning I use the ember-rails gem.
how are you packaging up the templates? are you sure it's even including the template in the browser?
You can find all the template names (keys) on Em.TEMPLATES object (see console in example below)
http://emberjs.jsbin.com/ejolaWOQ/1/edit
Ok,
I figured something out that works, you want to do:
<!-- note, did this in emblem, not sure if it translates to handlebars -->
{{ render 'nameOfController' someOptionalModel templateName='someDirectory/someTemplate' }}
Rails provides an awesome way to inspect variable contents in a template: <%= foo.inspect %>. Is that possible to do the same in Django? {% debug %} is a bit too messy.
There is a similar thread that has a number of good suggestions. If {% debug %} is unappealing, then it might be easier to inspect the variables in the view prior to the template rendering the page with the variables in question.
I was thinking about putting my static pages in the database (simple model of url, title and content) and then having a basic base_static.html template - making them super easy to edit (from admin interface) if necessary.
I know you can easily escape html like so:
{{ content|safe }}
or
{% autoescape off %}
{{ content }}
{% endautoescape %}
But I need to be able to use some of the template language in the static pages, e.g. a simple for loop to go over variables passed to it from the view.
Is this possible, or would you recommend simply using templates to serve the static pages?(They won't change that much ever)
Thank you for your help.
If you want to store templates in db (and that is what you want if you want to use a template language) you can use this app : django-dbtemplates.
Check this question: Extending Django Flatpages to accept template tags
You may get some ideas from the solution exposed there