Jekyll - show images & text in slider - yaml

I am using Bootstrap-Carousel.
Unfortunately, the data from front-matter is not being rendered.
index.html:
...
carousel:
a:
image: home/athenaBeta.jpeg
text: random text 1
b:
image: home/transport.jpeg
text: |
random text 2
c:
image: home/coffee.jpeg
text: |
random text 3
---
{% include hero-carousel.html %}
...
hero-carousel.html:
<div id="carousel" class="carousel slide" data-ride="carousel" pause="false">
<div class="carousel-inner text-center">
{% for news in page.carousel %}
{% capture image %}
{% assign img = news.image %}
{% endcapture %}
<div class="item img-cover img-fixed {% if forloop.index == 0 %}active{% endif %}" style="background-image:url({{ image }})">
<h2>{{ news.text }}</h2>
</div>
{% capture i %}{{ i | plus:1 }}{% endcapture %}
{% endfor %}
</div>
<a class="left carousel-control" href="#carousel" role="button" data-slide="prev">
<span class="fa glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel" role="button" data-slide="next">
<span class="fa glyphicon-chevron-right"></span>
</a>
<a class="arrow-down" href="#content">
<span class="fa glyphicon-chevron-down"></span>
</a>
</div>
It renders the three slides, however, none of the images or text is rendered. The output I get in browser is as below:
<div id="carousel" class="carousel slide" data-ride="carousel" pause="false">
<div class="carousel-inner text-center">
<div class="item img-cover img-fixed " style="background-image:url(
)">
<h2></h2>
</div>
<div class="item img-cover img-fixed " style="background-image:url(
)">
<h2></h2>
</div>
<div class="item img-cover img-fixed " style="background-image:url()">
<h2></h2>
</div>
</div>
<a class="left carousel-control" href="#carousel" role="button" data-slide="prev">
<span class="fa glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel" role="button" data-slide="next">
<span class="fa glyphicon-chevron-right"></span>
</a>
<a class="arrow-down" href="#content">
<span class="fa glyphicon-chevron-down"></span>
</a>
</div>

When you loop in page.caroussel, you receive things like :
{{ news | inspect }}
==> ["a", {"image"=>"home/athenaBeta.jpeg", "text"=>"random text 1"}]
which is an array containing two elements.
In order to reach your image, you can do {% assign img = news[1].image %}, but you'd better refactor a little :
...
carousel:
- image: home/athenaBeta.jpeg
text: random text 1
- image: home/transport.jpeg
text: |
random text 2
- image: home/coffee.jpeg
text: |
random text 3
---
<div id="carousel" class="carousel slide" data-ride="carousel" pause="false">
<div class="carousel-inner text-center">
{% for news in page.carousel %}
<div class="item img-cover img-fixed {% if forloop.first %}active{% endif %}" style="background-image:url('{{ news.image }}')">
<h2>{{ news.text }}</h2>
</div>
{% endfor %}
</div>

Related

Why are images not showing until the window is resized?

I am utilizing the modal from Zurb Foundation and some Liquid. Running into a strange issue. Images in the modal are being rendered to the DOM, but only show up when the screen is resized either smaller or larger.
Here is the code I am working with (yes, some elements have in-line styles specified).
<div class="grid-x align-middle grid-margin-x grid-margin-y small-up-1 medium-up-2 large-up-3 padding text-center">
{% for item in this.items %}
<div data-open="wa-project-{{forloop.index}}" class="cell" style="background-image:url('{{item['Image1']}}?mode=max&height=270'); height: 270px; width: 340px; background-size:cover; background-position:center; background-color:#00577d; margin: 12px auto;">
<div class="grid-y" style="height:270px; width:100%; background-color:rgba(0,25,36,.5)">
<div class="cell auto"></div>
<div class="cell shrink padding">
<div><a class="color-white" alt="{{item['Name']}} link">{{item['Name']}}</a></div>
<hr style="width: 125px; margin: 20px auto 0 auto; border-top-color: #8dd535">
</div>
<div class="cell auto"></div>
</div>
</div>
<!-- Modal -->
<div class="reveal" id="wa-project-{{forloop.index}}" data-reveal data-animation-in="scale-in-up" data-overlay="true">
<div class="orbit" role="region" aria-label="GoMedia Projects" data-orbit>
<div class="orbit-controls">
<button class="orbit-previous"><span class="show-for-sr">Previous Slide</span>◀︎</button>
<button class="orbit-next"><span class="show-for-sr">Next Slide</span>▶︎</button>
</div>
<ul class="orbit-container">
{% if item.image1 != "" %}
<li class="orbit-slide is-active">
<figure class="orbit-figure">
<img class="orbit-image" src="{{item.image1}}?mode=max&width=600" alt="space">
</figure>
</li>
{% endif %}
{% if item.image2 != "" %}
<li class="orbit-slide">
<figure class="orbit-figure">
<img class="orbit-image" src="{{item['Image2']}}?mode=max&width=600" alt="Space">
</figure>
</li>
{% endif %}
{% if item.image3 != "" %}
<li class="orbit-slide">
<figure class="orbit-figure">
<img class="orbit-image" src="{{item['Image3']}}?mode=max&width=600" alt="Space">
</figure>
</li>
{% endif %}
{% if item.image4 != "" %}
<li class="orbit-slide">
<figure class="orbit-figure">
<img class="orbit-image" src="{{item['Image4']}}?mode=max&width=600" alt="Space">
</figure>
</li>
{% endif %}
</ul>
</div>
<h2 class="fontsize-30">{{item.name}}</h2>
<hr style="width: 100%; border-top-color: #8dd535">
<p>{{item.description}}</p>
<button class="close-button" data-close aria-label="Close modal" type="button">
<i class="fas fa-times-circle"></i>
</button>
</div>
{% endfor %}
</div>
I've been researching for a bit, but have not found an answer. A height and width is specified for the images in the CSS. I am seeing it happen across multiple browsers: Firefox, Chrome, Safari. I have even tried starting from scratch with the Zurb Foundation template for the modal to no avail.

django AttributeError: 'str' object has no attribute 'field'

I am getting this error while submitting an ajax request using django.
The funny thing is if I execute these commands by hand when the debugger hits it works.
Here is the views.py
def lhr_search_custodians(request):
print request
print request.GET
print "blah"
# pdb.set_trace()
if request.method == 'GET':
search_text = request.GET.get('search_text')
else:
search_text = ''
custodians = Person.objects.filter(last_name__contains=search_text)
context = {'custodians': custodians}
return render(request, 'corpsec/legalholdrequests/create.html', context)
Here is the javascript query.js
$(function () {
$('#custodian_search').keyup(function (){
console.log("search fired!!!");
$.ajax({
url: "new/search_custodians",
type: "GET",
data: {
'search_text' : $('#custodian_search').val(),
'csrfmiddlewaretoken' : $("input[name=csrfmiddlewaretoken]").val()
},
success : searchSuccess,
dataType: 'html',
error: function(xhr, errmsg, err) {
$('#results');
}
});
});
});
function searchSuccess(data, textStatus, jqXHR) {
$('$search_results').html(data);
}
this is the template create.html
{% extends "blackbox/show.html" %}
{% load static from staticfiles %}
{% load formtags %}
{% block title %}
New Legal Hold Request | {{ block.super }}
{% endblock title %}
{% block javascript %}
{{ block.super }}
{% endblock javascript %}
{% block show_header_title %}
<h4>
New Legal Hold Request
</h4>
{% endblock show_header_title %}
{% block tab_menu %}
<li class="tab">
<a id="id_modal_matter"
href="#matter">
Matter
</a>
</li>
<li class="tab">
<a id="id_modal_custodians"
href="#custodians">
Custodians
</a>
</li>
<li class="tab">
<a id="id_modal_electronic_databases"
href="#databases">
Electronic Databases
</a>
</li>
<li class="tab">
<a id="id_modal_collection"
href="#collection">
Collection
</a>
</li>
{% endblock tab_menu %}
{% block tab_content %}
<form action="/corpsec/legalholdrequests/new"
role="form"
method="post">
<span id="csrfmiddlewaretoken">{% csrf_token %}</span>
{% if form.errors %}
<div class="alert alert-dismissable alert-danger">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Error.</strong> Please correct the following errors:
<small>{{ form.errors }}</small>
</div>
{% endif %}
<div class="row">
<div class="col s12">
<button id="id_form_submit"
type="submit"
class="btn right">
Submit
</button>
</div>
</div>
<div class="row">
<div id="matter" class="col s12">
<div class="row">
<div class="col s12 m8 offset-m2">
<div class="card">
<div class="card-content">
{{ form.matter_name|bsf_field }}<br/>
{{ form.matter_number|bsf_field }}<br/>
{{ form.matter_category|bsf_field }}<br/>
{{ form.priority_rating|bsf_field }}<br/>
{{ form.preservation|bsf_field }}<br/>
{{ form.issue_start|bsf_field }}<br/>
{{ form.issue_stop|bsf_field }}<br/>
{{ form.market_area|bsf_field }}<br/>
{{ form.attorney|bsf_field }}<br/>
{{ form.paralegal|bsf_field }}<br/>
{{ form.risk_manager|bsf_field }}<br/>
{{ form.category|bsf_field }}<br/>
</div>
</div>
</div>
</div>
</div>
<div id="custodians" class="col s12">
<div class="row">
<!-- search card -->
<div class="col s12 m3">
<div class="card">
<div class="card-content">
<span class='card-title'>Search Custodians</span>
<script src="{% static 'js/ldap-lookup.js' %}" type="text/javascript"></script>
<script src="{% static 'js/custodian_query.js' %}" type="text/javascript"></script>
{% csrf_token %}
<input type="text" id='custodian_search' name="search">
</div>
</div>
</div>
<!-- results section placeholder for now-->
<div class="col s12 m6">
<div class="card">
<div class="card-content">
<span class="card-title"> Results</span>
<ul id="search_results">
</ul>
</div>
</div>
</div>
<!-- action section -->
<div class="col s12 m3">
<div class="card">
<div class="card-content">
<span class="card-title">Action</span>
</div>
</div>
</div>
</div>
</div>
<div id="databases" class="col s12">
<div class="row" class='database_1'>
<div class="col s12 m8 offset-m2">
<div class="card">
<div class="card-content">
<div class="row">
{{ database_and_criteria_1.database|bsf_field }}<br/>
{{ database_and_criteria_1.criteria|bsf_field }}<br/>
</div>
</div>
<div class="card-action">
<button class='btn waves-effect waves-light' id='show_next_button' type="button" name="button">Add Database and Criteria</button>
</div>
</div>
</div>
</div>
<div class="row" id='database_2' style="display: none;">
<div class="col s12 m8 offset-m2">
<div class="card">
<div class="card-content">
<div class="row">
{{ database_and_criteria_2.database|bsf_field }}<br/>
{{ database_and_criteria_2.criteria|bsf_field }}<br/>
</div>
</div>
<div class="card-action">
<button class='btn waves-effect waves-light' id='show_next_button_2' type="button" name="button">Add Database and Criteria</button>
<button class='btn waves-effect waves-light red' id='remove_db_criteria_2' type="button" name="button">Remove</button>
</div>
</div>
</div>
</div>
<div class="row" id='database_3' style="display: none;">
<div class="col s12 m8 offset-m2">
<div class="card">
<div class="card-content">
<div class="row">
{{ database_and_criteria_3.database|bsf_field }}<br/>
{{ database_and_criteria_3.criteria|bsf_field }}<br/>
</div>
</div>
<div class="card-action">
<button class='btn waves-effect waves-light red' id='remove_db_criteria_3' type="button" name="button">Remove</button>
</div>
</div>
</div>
</div>
</div>
<div id="collection" class="col s12">
<div class="row">
<div class="col s12 m8 offset-m2">
<div class="card">
<div class="card-content">
<h4>Files<br/></h4>
{{ collection_form.email|bsf_field }}<br/>
{{ collection_form.netshare|bsf_field }}<br/>
{{ collection_form.computer_data|bsf_field }}<br/>
{{ collection_form.group_shares|bsf_field }}<br/>
{{ collection_form.pst_files|bsf_field }}<br/>
{{ collection_form.mobile_device|bsf_field }}<br/>
{{ collection_form.drive_cam_event_number|bsf_field }}<br/>
{{ collection_form.other_data_instructions|bsf_field }}<br/>
<h4>Processing</h4><br/>
{{ collection_form.processing_deadline|bsf_field }}<br/>
{{ collection_form.emails_attachments|bsf_field }}<br/>
{{ collection_form.everything|bsf_field }}<br/>
{{ collection_form.dedupe_matter|bsf_field }}<br/>
{{ collection_form.dedupe_custodian|bsf_field }}<br/>
{{ collection_form.keywords|bsf_field }}<br/>
{{ collection_form.archive_start|bsf_field }}<br/>
{{ collection_form.archive_stop|bsf_field }}<br/>
{{ collection_form.review_platform_external|bsf_field }}<br/>
{{ collection_form.delivery_instructions|bsf_field }}<br/>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<script type="text/javascript">
$('#show_next_button').click(function() {
document.getElementById('database_2').style.display = 'block';
});
$('#show_next_button_2').click(function() {
document.getElementById('database_3').style.display = 'block';
});
$('#remove_db_criteria_2').click(function() {
document.getElementById('database_2').style.display = 'none';
});
$('#remove_db_criteria_3').click(function() {
document.getElementById('database_3').style.display = 'none';
});
</script>
{% endblock tab_content %}

Change Index BLog to Directory Blog [Jekyll]

How do I replace a blog list of index
example: mysite.com to mysite.com/blog
I have copied from the index and make myste.com/blog.html , but it does not work
---
layout: default
---
<div class="home">
<div class="site-header-container {% if site.cover %}has-cover{% endif %}" {% if site.cover %}style="background-image: url({{ site.cover | prepend: site.baseurl }});"{% endif %}>
<div class="scrim {% if site.cover %}has-cover{% endif %}">
<header class="site-header">
<h1 class="title">{{ site.title }}</h1>
{% if site.subtitle %}<p class="subtitle">{{ site.subtitle }}</p>{% endif %}
</header>
</div>
</div>
<div class="wrapper">
<ul class="post-list">
{% for post in paginator.posts %}
<li>
<h2>
<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
</h2>
<section class="post-excerpt" itemprop="description">
<p>{{ post.content | strip_html | truncatewords: 50 }}</p>
</section>
<section class="post-meta">
<div class="post-date">{{ post.date | date: "%B %-d, %Y" }}</div>
<div class="post-categories">
{% if post.categories.size > 0 %}in {% for cat in post.categories %}
{% if site.jekyll-archives %}
{{ cat | capitalize }}{% if forloop.last == false %}, {% endif %}
{% else %}
<span>{{ cat | capitalize }}</span>{% if forloop.last == false %}, {% endif %}
{% endif %}
{% endfor %}{% endif %}
</div>
</section>
</li>
{% if forloop.last == false %}
<hr>
{% endif %}
{% endfor %}
</ul>
<nav class="pagination" role="navigation">
<p>
{% if paginator.next_page %}
<a class="newer-posts" href="{{ site.baseurl }}/page{{paginator.next_page}}">
<span class="fa-stack fa-lg">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-angle-double-left fa-stack-1x fa-inverse"></i>
</span>
</a>
{% else %}
<span class="fa-stack fa-lg">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-angle-double-left fa-stack-1x fa-inverse"></i>
</span>
{% endif %}
<span class="page-number">Page {{ paginator.page }} of {{ paginator.total_pages }}</span>
{% if paginator.previous_page %}
{% if paginator.page == 2 %}
<a class="newer-posts" href="{% if site.baseurl %}{{ site.baseurl }}{% endif %}/">
<span class="fa-stack fa-lg">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-angle-double-right fa-stack-1x fa-inverse"></i>
</span>
</a>
{% else %}
<a class="newer-posts" href="{{ site.baseurl }}/page{{paginator.previous_page}}">
<span class="fa-stack fa-lg">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-angle-double-right fa-stack-1x fa-inverse"></i>
</span>
</a>
{% endif %}
{% else %}
<span class="fa-stack fa-lg">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-angle-double-right fa-stack-1x fa-inverse"></i>
</span>
{% endif %}
</p>
<p>
View All Posts by Category
</p>
</nav>
</div>
</div>
Open your config file, and set baseurl as /blog
baseurl: "/blog"
And use prepend:site.baseurl everywhere, just like you have used in above code
{{ site.baseurl }}/category/{{ cat }}

Interpolating variables in jekyll/liquid with jekyll-assets

I have a list of articles in my data and one of the fields is a link to an image. I'm using jeykll-assets, and I would like to load the images using the asset_path. However, the following isn't working:
{% for article in site.data.press %}
<div class="press-item">
<div class="press-image">
<div class="centerit"></div>
<a href="{{ article.url }}" target="_blank">
<img src="{% asset_path article.logo %}" />
</a>
</div>
<div class="press-excerpt">
<a href="{{ article.url }}" target="_blank">
<p>{{ article.title }}</p>
</a>
</div>
<div class="date">{{ article.date }}</div>
</div>
{% endfor %}
Specifically <img src="{% asset_path article.logo %}" /> because it doesn't load article.logo dynamically. What's the correct way to do this?
Use brackets like this : <img src="{% asset_path {{ article.logo }} %}" />
See https://github.com/jekyll/jekyll-assets#liquid-variables

Get template block contents and call from ajax

I'm using django 1.9 and python 3. My english also isn't the best, so excuse the question if it is formulated bad.
I'm working on making my website a single-page application. I need to get the {% block %} contents of a given template, and then send that as a HttpResponse so that ajax can pick it up and inject it into the page.
I've tried using the answer from this question: Django - how to get the contents of a {% block %} tag from a template
But upon trying to fetch the contents of a block in my view like so:
response_data[content] = get_block_source('profile/login.html', 'content')
if request.is_ajax():
return HttpResponse(
json.dumps(response_data),
content_type="application/json"
)
I just get this error from django, no matter what I do:
ValueError at /login/ Template block content not found
The contents of the block don't even make it to the ajax call, what gives?
EDIT:
I'll include my "content" block here:
in my template:
{% extends 'base.html' %}
{% block content %}
<div class="big-title text">Log in</div>
<div class="form-container">
<form name="login-form" id="user" method="post" action="/login/" enctype="multipart/form-data" class="text">
{% csrf_token %}
<div class="title">Enter your credentials</div>
<div class="form-row">
<div class="form-flex">
<div class="field-container">
<div class="field-input-container">
<div class="field-label accent">Username</div>
<div class="field-input">
<input class="field-input-element" type="text" name="username" />
</div>
</div>
<div class="field-help">Your username is always lowercase.</div>
</div>
</div>
<div class="form-flex">
<div class="field-container" style="height: 110px">
<div class="field-input-container">
<div class="field-label accent">Password</div>
<div class="field-input">
<input class="field-input-element" type="password" name="password" />
</div>
</div>
<div class="field-help"></div>
</div>
</div>
</div>
<div class="form-button-container">
<div class="form-error"></div>
<div class="form-message"></div>
<input type="submit" name="submit" value="Accept" class="button form-button"/>
</div>
</form>
</div>
{% endblock %}
In my base (base.html)
<body>
<div id="modal-container">
<div id="modal-overlay">
<div id="modal-items">
</div>
</div>
</div>
<div id="wrapper">
<header>
<div id="header-title" class="text accent">App name</div>
<div id="header-nav">
<nav>
{% if user.is_authenticated %}
Home
Feed {% if request.user.is_superuser %}
Admin {% endif %}
N
<a href="/{{ request.user }}" class="header-avatar-small-a">
<div class="text header-greeting">Hi, {{ user.userprofile.display_name }}</div>
<div class="header-avatar-small">
{% if not user.userprofile.avatar == '' %}
<img src="{{ MEDIA_URL }}users/{{ user }}/avatar" alt=""> {% else %}
<img src="{{ MEDIA_URL }}users/avatar" alt=""> {% endif %}
</div>
</a>
{% else %}
Log in
Create account {% endif %}
</nav>
</div>
<div class="progress">
<div id="header-progress" class="fill"></div>
</div>
</header>
<main>
{% block content %} {% endblock %}
</main>
<footer></footer>
</div>
</body>
</html>
Template source is the template actual HTML, not the file reference

Resources