How to fetch content of pages having specific template? - bolt-cms

I want to fetch content of contenttype pages which are using a template page_with_sidebar.twig?
How do I do that?
e.g
{% setcontent a = 'pages' [some filter here to retrieve specific templated pages] %}

{% setcontent side_pages = 'pages' where { template: 'page_with_sidebar.twig' } %}

Related

Jekyll how can I use site.data.+variable?

I would like to know if there's a way to use a variable after a data call in Jekyll?
Like this:
{% assign variable = items %}
{% assign images = site.data.folder.variable %}
You can use a variable as an object key using this notation:
{% assign images = site.data.folder[variable] %}

Use multiple block and views in django templates

I am new to django, and I see that you could create templates that you could populate in views.
You could also create some basic.htm that everyone extends...
Let say I have two pages: (django demo)
List of all questions
Detail of the question.
Now I would like to create "one page" that have first view as sidebar and another as a "detail- right" view.
I would like that on clicking on the list in sidebar change right vies.
It would be nice, if I could use different views (inside views.py) for loading separate templates.
I wish for base html would be something like this :
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Makro Zadravec</title>
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'demo/css/bootstrap.min.css.css' %}" />
</head>
<body class="body" style="background-color: #f6f6f6">
<div>
<h1> This is title</h1>
</div>
<div>
{% block sidebar %}
{% endblock %}
</div>
<div>
{% block content %}
{% endblock %}
</div>
</body>
</html>
And then I would have template for blocks:
content
sidebar
in separate views.
Apart from styling here is the logic you can follow this
as you said you already have template which already loaded list of question then your base view would return all the question object as queryset.
First of all, you don't need to write separate template because you can handle this
{% block content %}
// this will load list of all question
{% endblock %}
{% block detail %}
// here display detail of question
{% endblock %}
create two urls to hit one without kwargs and other with kwargs (if you use django version < 2.0 you need to use url instead of path)
path('target/', QuestionView.as_view(), name='target-list'),
path('target/<int:pk>', QuestionView.as_view(), name='target-detail')
Now in view file you just need to handle the kwargs:
class QuestionView(TemplateView):
template_name = "template.html"
model = Question
def get_context_data(self, **kwargs):
context = super(QuestionView, self).get_context_data(**kwargs)
context['question_list'] = #your queryset to list question#
pk = kwargs.get('pk', None) # this will return pk (id of question) if hit url otherwise None
if pk:
context['question_detail'] = #your queryset to get question-detial#
return context
so if you hit url with kwargs it will return both list of question and detail with it as context in template which you can access as below:
{% block content %}
# access question_list to list out all question
{% endblock %}
{% block detial %}
{% if question_detail %} // if question_detail context passed from view
# add detail of question by accessing question_detail
{% endif %}
{% endblock %}
You can do this based on one view.
Create variable called 'question' in your view which at start is defined as an empty string. Then if someone click on some question on sidebar block you can make url with parameter with id of question to show details ('/page/?question=1') or you can store this id in session, as you want. And call same view another time. Then in view you check if you get parameter in url or if it's stored in session and if it's true you assign question object (which you get by id) to variable 'question'. Send this variable to template. In template you render sidebar always and check if variable 'question' is not equal to empty string then you render details for question.
Something like this:
{% block sidebar %}
...
{% endblock %}
{% if question != '' %}
{% block content %}
...
{% enblock %}
{% endif %}

Flask, jinja2 - Dynamically append templates one after another

I am building a chatbot. There are few child templates like login.html, messages.html, transaction.html, etc. I want to append these templates in base.html dynamically. I am extending base.html in all these templates. My problem is only one template is rendered at a time. Is there any solution for appending these templates one after another? I have used {%include%} but it's a static approach. I need dynamic.
printer.py looks like -
#app.route('/respond', methods=['GET','POST'])
def respond_def():
message = request.form['message_input']
if message == "l":
return render_template('printer/login.html')
elif message == "t":
return render_template('printer/transactionID.html')
base.html looks like -
//some code here
<li>
{% block template %}{% endblock %}
</li>
//some code here
message.html looks like -
{% extends "base.html" %}
{% block template %}
<div> Message template called </div>
{% endblock %}
I resolved it.
I made a list of templates in printer.py and then appended those templates in base.html whenever user asked for it.
printer.py
dictionary = []
// append name of template in this whenever needed.
return render_template('printer/base.html', dictionary=dictionary)
base.html
{% for d in dicts %}
{% set template = 'printer/' + d + '.html' %}
// can add conditions for different templates
{% include template %}
{% endfor %}

In Jekyll, I want to loop through items in a list and set assign tags for each item

In Jekyll, I want to loop through items in a list and assign variables to each of them.
In a data file, my list looks like this:
entries:
- title: Sidebar
subcategories:
- title: Overview
items:
- title: Introduction
url: /introduction/
linkname: intro
- title: Release Notes
url: /release_notes/
linkname: relnote
My looping logic looks like this:
{% for entry in sidebar %}
{% for subcategory in entry.subcategories %}
{% for item in subcategory.items %}
{% assign item.linkname = "{{item.title}}" %}
{% endfor %}
{% endfor %}
{% endfor %}
Then I want to insert the variable using {{intro}} or {{relnote}} on a page. Using this method, I should be able to generate variables for all the items in my sidebar, making it easy to embed links in my content.
However, this method doesn't seem to work. Nothing appears for the variable when I insert it. What am I doing wrong?
With Jekyll/Liquid, you cannot create a variable name from a variable value.

How to navigate json objects in django templating language

If I pass in a json object from my view i.e. return render(request, 'development/index.html', {'data': data}), where data is {a:{"colA":12,"colB":13"},b:{"ColA":1","colB":2"}}, how can I populate a select in index.html with all the values in ColA?
You should be populating selects with options using django forms, not in template.
But if you absolutely have to do it in template then you can loop through dict like this:
{% for item in data.iteritems %}
{{ item.colA }}
{% endfor %}